Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

书写更好的 Python 代码 #3

Open
lilydjwg opened this issue Sep 14, 2015 · 0 comments
Open

书写更好的 Python 代码 #3

lilydjwg opened this issue Sep 14, 2015 · 0 comments

Comments

@lilydjwg
Copy link

  • 使用绝对导入(from __future__ import absolute_import)来避免包名冲突
  • 通过继承 object 来使用 new-style class
  • 将标准库、第三方库与本项目的 import 语句使用空行分组
  • logging 记录日志时第一个参数是格式化字符串,不是消息本身。如
logger.info('something bad happened: %r', exc)
  • sorted(PagesToTranslate, self.sort_result) 使用 key=self.sort_result 来明确参数的用途(这种写法在 Python 3 中已经不允许)
  • 行末不要加分号
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants