首页 > 编程语言 > 详细

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

时间:2020-06-21 12:46:28      阅读:63      评论:0      收藏:0      [点我收藏+]

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别名

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!