项目当中用到 https://github.com/Cirru/sepal.py
贴一点笔记.html
社区模块方案选用 pip, 在 PyPI 上查询模块, 入门教程:
http://peterdowns.com/posts/first-time-with-pypi.htmlnode
python setup.py register -r pypitest python setup.py sdist upload -r pypitest python setup.py register -r pypi python setup.py sdist upload -r pypi
Python 不支持尾递归优化, 社区有提供优化的脚本(不过实际项目使用有问题):
http://calebmadrigal.com/tail-call-optimization-in-python/python
一样模仿 Clojure 能够在 REPL 当中测试函数, 那么刷新模块像是这样:git
import sys if 'myModule' in sys.modules: del sys.modules["myModule"]
http://stackoverflow.com/a/3194343/883571github
AST 的文档比较丰富的, 不过也比较庞杂, 实现起来估计也会累
考虑到要实现的 AST 的量, 我考虑暂停试验算了.
http://eli.thegreenplace.net/2009/11/28/python-internals-working-with-python-asts/
https://pypi.python.org/pypi/astdump/3.3
http://greentreesnakes.readthedocs.org/en/latest/tofrom.html
https://docs.python.org/2/library/ast.htmlexpress
import ast a = ast.literal_eval("[1,2,3,4]") //evaluate an expression safely.
import ast source = '2 + 2' node = ast.parse(source, mode='eval') ast.dump(node)
http://stackoverflow.com/a/13350121/883571函数
还能够用 codegen.to_source
生成代码:post
import ast import codegen ast.parse('print(1 + 2)') # return AST ast.dump(ast.parse('print(1 + 2)')) # return readable AST codegen.to_source.dump(ast.parse('print(1 + 2)')) # generate code
AST 当中用到一些 keyword arguments:
http://stackoverflow.com/a/1419160/883571测试
Python 模块引用一句 Module Search Path 查找, 能够从 sys.path
查看
https://docs.python.org/2/tutorial/modules.html#the-module-search-path优化
package 的目录会有 __init__.py
文件, 引入须要暴露的模块
好比这样是把 sepal.py
文件的 transform
函数暴露出去
from sepal import transform
with open ("data.txt", "r") as myfile: data=myfile.read().replace('\n', '')
http://stackoverflow.com/a/8369345/883571
安装 nosetests 来进行测试
http://pythontesting.net/framework/nose/nose-introduction/
http://pythontesting.net/framework/unittest/unittest-introduction/
install_requires
字段用于声明依赖
http://www.scotttorborg.com/python-packaging/dependencies.html