with open(‘file_path’, ‘a+’) as f:
f.write(’test’)- [Part.1.F.deal-with-forward-references(**如何从容应对含有过多 “过早引用” 的知识?**)](https://github.com/selfteaching/the-craft-of-selfteaching/blob/master/Part.1.F.deal-with-forward-references.ipynb) - 不懂也要硬着头皮读完:读不懂也要读完,然后重复很多遍 - 磨练 “只字不差” 的能力 - 好的记忆力很重要 - 尽快开始整理归纳总结 - 先关注使用再研究原理 - 尊重前人的总结和建议 - PEP - [Part.1.G.The-Python-Tutorial-local(**官方教程:The Python Tutorial**)](https://github.com/selfteaching/the-craft-of-selfteaching/blob/master/Part.1.G.The-Python-Tutorial-local.ipynb) - 官方文档中最重要的链接 - Tutorial: https://docs.python.org/3/tutorial/index.html - Library Reference: https://docs.python.org/3/library/index.html - 为什么一定要阅读官方文档:全面,第一查询对象只能是官方文档 - [Part.2.A.clumsy-and-patience(**笨拙与耐心**)](https://github.com/selfteaching/the-craft-of-selfteaching/blob/master/Part.2.A.clumsy-and-patience.ipynb) - 四个阶段:学练用造 - 绝对不做预算不够的事情 - 事跟天分与智商几乎没有任何关系 - [Part.2.B.deliberate-practicing(**刻意练习**)](https://github.com/selfteaching/the-craft-of-selfteaching/blob/master/Part.2.B.deliberate-practicing.ipynb) - 刻意思考哪里需要刻意练习 - [Part.2.C.why-start-from-writing-functions(**为什么从函数开始?**)](https://github.com/selfteaching/the-craft-of-selfteaching/blob/master/Part.2.C.why-start-from-writing-functions.ipynb) - [Part.2.D.1-args(**关于参数(上)**)](https://github.com/selfteaching/the-craft-of-selfteaching/blob/master/Part.2.D.1-args.ipynb) - 函数参数传递的是 value,例外:可变容器(如列表) - [Part.2.D.2-aargs(**关于参数(下)**)](https://github.com/selfteaching/the-craft-of-selfteaching/blob/master/Part.2.D.2-aargs.ipynb) - Positional - Arbitrary Positional 类似列表 - Keyword - Arbitrary Keyword 类似字典 - [Part.2.D.3-lambda(**化名与匿名**)](https://github.com/selfteaching/the-craft-of-selfteaching/blob/master/Part.2.D.3-lambda.ipynb) - `lambda_expr ::= "lambda" [parameter_list] ":" expression` - 作为某函数的返回值 - 作为某函数的参数 - [Part.2.D.4-recursion(**递归函数**)](https://github.com/selfteaching/the-craft-of-selfteaching/blob/master/Part.2.D.4-recursion.ipynb) - 递归函数(Recursive Functions)—— 那些在自身内部调用自身的函数。 - [Part.2.D.5-docstrings(**函数的文档**)](https://github.com/selfteaching/the-craft-of-selfteaching/blob/master/Part.2.D.5-docstrings.ipynb) - Docstring,必须在函数定义的内部语句块的开头,也必须与其它语句一样保持相应的缩进(Indention) - `help(function_name)` - `function_name.__doc__` - 书写 Docstring 的规范 - PEP 257: Docstring Convensions https://www.python.org/dev/peps/pep-0257/ - PEP 258: Docutils Design Specification https://www.python.org/dev/peps/pep-0258/ - example
javascript
def say_hi(*names, greeting=‘Hello’, capitalized=False):
"""
Print a string, with a greeting to everyone.
:param *names: tuple of names to be greeted.
:param greeting: ‘Hello’ as default.
:param capitalized: Whether name should be converted to capitalized before print. False as default.
:returns: None
"""
- Sphinx 版本的 Docstring 规范 - http://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html - https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html - [Part.2.D.6-modules(**保存到文件的函数**)](https://github.com/selfteaching/the-craft-of-selfteaching/blob/master/Part.2.D.6-modules.ipynb) - 模块 - 模块文件系统目录检索顺序 - 引入指定模块中的特定函数
javascript
from mycode import *
from mycode import is_prime
from mycode import is_prime as isp
import mycode as m
- [Part.2.D.7-tdd(**测试驱动的开发**)](https://github.com/selfteaching/the-craft-of-selfteaching/blob/master/Part.2.D.7-tdd.ipynb) - TDD - https://docs.python.org/3/library/doctest.html - https://docs.python.org/3/library/unittest.html - [Part.2.D.8-main(**可执行的 Python 文件**)](https://github.com/selfteaching/the-craft-of-selfteaching/blob/master/Part.2.D.8-main.ipynb) - [Part.2.E.deliberate-thinking(**刻意思考**)](https://github.com/selfteaching/the-craft-of-selfteaching/blob/master/Part.2.E.deliberate-thinking.ipynb) - 刻意思考哪儿需要刻意练习 - 这东西能用在哪儿呢? - https://en.wikipedia.org/wiki/MoSCoW_method - Must have - Should have - Could have - Won't have - [Part.3.A.conquering-difficulties(**战胜难点**)](https://github.com/selfteaching/the-craft-of-selfteaching/blob/master/Part.3.A.conquering-difficulties.ipynb) - 困难幻觉:所有的难点,事实上都可以被拆解成更小的单元,而后在逐一突破的时候,就没那么难了。逐一突破全部完成之后,再拼起来重新审视的时候就会发现那所谓的难常常只不过是错觉、幻觉而已 - [Part.3.B.1.classes-1(**类 —— 面向对象编程**)](https://github.com/selfteaching/the-craft-of-selfteaching/blob/master/Part.3.B.1.classes-1.ipynb) - 面向对象编程(Object Oriented Programming, OOP) - 对象,封装,抽象 - 界面,属性,方法 - 继承,类,子类,实例 - [Part.3.B.2.classes-2(**类 —— Python 的实现**)](https://github.com/selfteaching/the-craft-of-selfteaching/blob/master/Part.3.B.2.classes-2.ipynb) - Defining Class - Inheritance - Overrides - Inspecting A Class - 1. help(object) - 2. dir(object) - 3. object.__dict__ - Encapsulation - [Part.3.B.3.decorator-iterator-generator(**函数工具**)](https://github.com/selfteaching/the-craft-of-selfteaching/blob/master/Part.3.B.3.decorator-iterator-generator.ipynb) - 迭代器、生成器和装饰器,这些都是函数工具。有人把它们称为 DIG(Decorator,Iterator,Generator) - 迭代器(Iterator) iter()
javascript
class Counter(object):
def init(self, start, stop):
self.current = start
self.stop = stop
def iter(self):
return self
def next(self):
if self.current > self.stop:
raise StopIteration
else:
c = self.current
self.current += 1
return c
...