Python 文档学习

1、在命令行执行Python脚本(获取输入)

import sys

print(sys.argv[1])

2、compile Python(编译Python)

  编译后,生成的文件是.pyc,但是要知道的是,不像C语言,编译后执行效率高,并且是编译成二进制;

  Python编译后只是加载快了,但是执行效率并不会增高;

3、dir()

    内部价模块名称,返回模块内定义的名称

>>> import builtins
>>> dir(builtins)  

4、常常在build_in的模块中看到__all__的一个列表,放在包的__init__中,它只有在使用以下方法导入模块时候生效:

__all__ = ["echo", "surround", "reverse"]


# 假设在另一个包中
from packagename import *
# 那这个操作会导入__all__列表中所有的模块

# 注意:原文的一段提示:Remember, there is nothing wrong with using from Package import specific_submodule!
# In fact, this is the recommended notation unless the importing module needs to use submodules with the same name from different packages.
# 也就是说,这个功能也是为了在不同的包中使用相同名称,如果没有这个需要,就没有必要也最好不要这样做。

  

原文地址:https://www.cnblogs.com/chenadong/p/10297933.html