模块是包含Python定义和语句的文件。文件名是带有后缀的模块名称
.py
创建
hello.py然后编写以下函数作为其内容:
def helloworld(): print "hello"
然后,你可以导入
hello:
>>> import hello>>> hello.helloworld()'hello'>>>
要对许多
.py文件进行分组,请将它们放在文件夹中。带有的任何文件夹
__init__.py都被
python视为模块,你可以将其称为包
|-HelloModule |_ __init__.py |_ hellomodule.py
|
你可以按照通常的方式在模块上使用import语句。



