[摘要]Python 最佳实践指南
admin
2023-07-31 00:36:43
0

文档地址 The Hitchhiker’s Guide to Python!

这份文档

12 目标对象:入门后,有一定基础的Pythonista关键词:最佳实践,Pythonic,各类工具介绍

粗粗粗略地过了一遍,大体捞了一些东西出来,大段大段英文太费眼了,回头细读在更新进来

浓缩版,20分钟可大体过完,然后根据自己需要去看详细的吧

整体内容还是很不错的,建议细读英文

PS:文档含有巨量的TODO(没写空白着待补充的),不过但从目录上来看还是很强大滴,相信完善后,会成为一份很牛逼的指南(难度比官方指南高一点点)


第零部分 Getting Started

链接

不解释,不翻译,自个看….真的没啥(每本入门书籍第一章…)


第一部分 Writing Great Code

Structuring Your Project

链接

import 最佳实践

Very bad

1234 [...]from modu import *[...]x = sqrt(4)  # Is sqrt part of modu? A builtin? Defined above?

Better

123 from modu import sqrt[...]x = sqrt(4)  # sqrt may be part of modu, if not redefined in between

Best

123 import modu[...]x = modu.sqrt(4)  # sqrt is visibly part of modu\’s namespace

Python中关于OOP的 观点

Decorators

12345678910111213 def foo():    # do something def decorator(func):    # manipulate func    return func foo = decorator(foo)  # Manually decorate @decoratordef bar():    # Do something# bar() is decorated

动态类型(Dynamic typing)

Avoid using the same variable name for different things.

Bad

1234 a = 1a = \’a string\’def a():    pass  # Do something

Good

1234 count = 1msg = \’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:

12345 Bad items = \’a b c d\’  # This is a string…items = items.split(\’ \’)  # …becoming a listitems = 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

1234 [...]from modu import *[...]x = sqrt(4)  # Is sqrt part of modu? A builtin? Defined above?

Better

123 from modu import sqrt[...]x = sqrt(4)  # sqrt may be part of modu, if not redefined in between

Best

123 import modu[...]x = modu.sqrt(4)  # sqrt is visibly part of modu\’s namespace

Python中关于OOP的 观点

Decorators

12345678910111213 def foo():    # do something def decorator(func):    # manipulate func    return func foo = decorator(foo)  # Manually decorate @decoratordef bar():    # Do something# bar() is decorated

动态类型(Dynamic typing)

Avoid using the same variable name for different things.

Bad

1234 a = 1a = \’a string\’def a():    pass  # Do something

Good

1234 count = 1msg = \’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:

12345 Bad items = \’a b c d\’  # This is a string…items = items.split(\’ \’)  # …becoming a listitems = set(items)  # …and then a set

可变和不可变类型(Mutable and immutable types)

字符串拼接最佳实践

Bad

相关内容

热门资讯

500 行 Python 代码... 语法分析器描述了一个句子的语法结构,用来帮助其他的应用进行推理。自然语言引入了很多意外的歧义,以我们...
定时清理删除C:\Progra... C:\Program Files (x86)下面很多scoped_dir开头的文件夹 写个批处理 定...
65536是2的几次方 计算2... 65536是2的16次方:65536=2⁶ 65536是256的2次方:65536=256 6553...
Mobi、epub格式电子书如... 在wps里全局设置里有一个文件关联,打开,勾选电子书文件选项就可以了。
scoped_dir32_70... 一台虚拟机C盘总是莫名奇妙的空间用完,导致很多软件没法再运行。经过仔细检查发现是C:\Program...
pycparser 是一个用... `pycparser` 是一个用 Python 编写的 C 语言解析器。它可以用来解析 C 代码并构...
小程序支付时提示:appid和... [Q]小程序支付时提示:appid和mch_id不匹配 [A]小程序和微信支付没有进行关联,访问“小...
Prometheus+Graf... 一,Prometheus概述 1,什么是Prometheus?Prometheus是最初在Sound...
python绘图库Matplo... 本文简单介绍了Python绘图库Matplotlib的安装,简介如下: matplotlib是pyt...
微信小程序使用slider实现... 众所周知哈,微信小程序里面的音频播放是没有进度条的,但最近有个项目呢,客户要求音频要有进度条控制,所...