python模块之间的代码元素的访问

1.一个模块本质就是一个文件,在模块中封装了很多代码元素。

1)导入所有内容:import语句

2)只导入一个元素,from import

3)如果名称有冲突 from import as

# @File    : world.py
# @Software: PyCharm
#coding=utf-8

x='你好'
y=True
z=20.0

# @File    : hello.py
# @Software: PyCharm
#coding=utf-8
from test_module import world
from test_module.world import x as x2
from test_module.world import z
x=100
y=20
print(y) #访问当前模块变量y
print(world.y)#访问world模块变量y
print(z)#访问world模块变量z
print(x2) #x2是world模块x别名

原文地址:https://www.cnblogs.com/JacquelineQA/p/13171993.html