#my_module.py
print('from the my_module.py')
money=1000
def read1():
print('my_module->read1->money',money)
def read2():
print('my_module->read2 calling read1')
read1()
def change():
global money
money=0
1.模块和包,同级下使用import导入
import a #导入a.py
a.read2() #执行a.py里面read2方法,这里的a是名称空间
2.包里面的变量和自己当下模块的变量不会冲突,如果使用自己模块下的直接用,引用模块的,使用引用名.变量(方法)
3.使用别名 import my_module as module
if file_format == 'xml':
import xmlreader as reader
elif file_format == 'cvs':
import csvreader as reader
data = reader.read_date(filename)
4. from my_module import read1 #从my_module中调用read1方法 ,如果当前模块有同名函数,那么就覆盖
5. 支持多行导入: from my_module import (read1, read2, money)