Be Pythonic

2015-11-02 kk 更多博文 » 博客 » GitHub »

原文链接 http://www.kkblog.me/notes/Be-Pythonic
注:以下为加速网络访问所做的原文缓存,经过重新格式化,可能存在格式方面的问题,或偶有遗漏信息,请以原文为准。


best practice

code style

  • encoding
  • pep8
  • linter, flake8

package

  • pip
  • virturalenv
  • setup.py

http://lingxiankong.github.io/blog/2013/12/23/python-setup/

testing

  • pytest
  • mock
  • tox

py2 py3

from __future__ import unicode_literals
from __future__ import absolute_import
  • six

https://pythonhosted.org/six/ http://woodpecker.org.cn/diveintopython3/porting-code-to-python-3-with-2to3.html

data structures

  • list
  • dict
  • set
  • tuple

Looping

built-in functions

  • list dict set tuple sorted
  • range enumerate zip
  • all any
  • type id
  • dir getattr setattr

Exception

  • try except
  • Look Before You Leap
  • Easier to ask forgiveness than permission

decorater

  • decorater
  • functools.wraps
  • functools.partial

library

  • datetime, date, time, dateutil
  • json

module

  • from xx import *
  • relative import
  • absolute import

flask

  • request response
  • context
  • read the source code

相关学习资源

https://github.com/wklken/stackoverflow-py-top-qa
http://pyzh.readthedocs.org/en/latest/index.html
http://xianglong.me/article/how-to-code-like-a-pythonista-idiomatic-python

博客

http://www.pythoner.com/
http://blog.xiayf.cn/
http://wklken.me/