文档地址 The Hitchhiker’s Guide to Python!
这份文档
1 2 |
目标对象:入门后,有一定基础的Pythonista 关键词:最佳实践,Pythonic,各类工具介绍 |
粗粗粗略地过了一遍,大体捞了一些东西出来,大段大段英文太费眼了,回头细读在更新进来
浓缩版,20分钟可大体过完,然后根据自己需要去看详细的吧
整体内容还是很不错的,建议细读英文
PS:文档含有巨量的TODO(没写空白着待补充的),不过但从目录上来看还是很强大滴,相信完善后,会成为一份很牛逼的指南(难度比官方指南高一点点)
第零部分 Getting Started
不解释,不翻译,自个看….真的没啥(每本入门书籍第一章…)
第一部分 Writing Great Code
Structuring Your Project
import 最佳实践
Very bad
1 2 3 4 |
[...] from modu import * [...] x = sqrt(4) # Is sqrt part of modu? A builtin? Defined above? |
Better
1 2 3 |
from modu import sqrt [...] x = sqrt(4) # sqrt may be part of modu, if not redefined in between |
Best
1 2 3 |
import modu [...] x = modu.sqrt(4) # sqrt is visibly part of modu's namespace |
Python中关于OOP的 观点
Decorators
1 2 3 4 5 6 7 8 9 10 11 12 13 |
def foo(): # do something def decorator(func): # manipulate func return func foo = decorator(foo) # Manually decorate @decorator def bar(): # Do something # bar() is decorated |
动态类型(Dynamic typing)
Avoid using the same variable name for different things.
Bad
1 2 3 4 |
a = 1 a = 'a string' def a(): pass # Do something |
Good
1 2 3 4 |
count = 1 msg = 'a string' def func(): pass # Do something |
It is better to use different names even for things that are related, when they have a different type:
1 2 3 4 5 |
Bad items = 'a b c d' # This is a string... items = items.split(' ') # ...becoming a list items = set(items) # ...and then a set |
可变和不可变类型(Mutable and immutable types)
字符串拼接最佳实践
Bad
粗粗粗略地过了一遍,大体捞了一些东西出来,大段大段英文太费眼了,回头细读在更新进来
浓缩版,20分钟可大体过完,然后根据自己需要去看详细的吧
整体内容还是很不错的,建议细读英文
PS:文档含有巨量的TODO(没写空白着待补充的),不过但从目录上来看还是很强大滴,相信完善后,会成为一份很牛逼的指南(难度比官方指南高一点点)
第零部分 Getting Started
不解释,不翻译,自个看….真的没啥(每本入门书籍第一章…)
第一部分 Writing Great Code
Structuring Your Project
import 最佳实践
Very bad
1 2 3 4 |
[...] from modu import * [...] x = sqrt(4) # Is sqrt part of modu? A builtin? Defined above? |
Better
1 2 3 |
from modu import sqrt [...] x = sqrt(4) # sqrt may be part of modu, if not redefined in between |
Best
1 2 3 |
import modu [...] x = modu.sqrt(4) # sqrt is visibly part of modu's namespace |
Python中关于OOP的 观点
Decorators
1 2 3 4 5 6 7 8 9 10 11 12 13 |
def foo(): # do something def decorator(func): # manipulate func return func foo = decorator(foo) # Manually decorate @decorator def bar(): # Do something # bar() is decorated |
动态类型(Dynamic typing)
Avoid using the same variable name for different things.
Bad
1 2 3 4 |
a = 1 a = 'a string' def a(): pass # Do something |
Good
1 2 3 4 |
count = 1 msg = 'a string' def func(): pass # Do something |
It is better to use different names even for things that are related, when they have a different type:
1 2 3 4 5 |
Bad items = 'a b c d' # This is a string... items = items.split(' ') # ...becoming a list items = set(items) # ...and then a set |
可变和不可变类型(Mutable and immutable types)
字符串拼接最佳实践
Bad