用一个例子说明python模块化的标准
时间:2021-08-30 14:29:11
收藏:0
阅读:18
#first.py X=99 #second.py import first print(first.X) first.X=88
这样做在second.py这个文件中对first.py这个文件当中的变量X进行了直接操作,很不安全。
恰当的方法是使用函数引用
#first.py X=99 def setX(new): global X X=new #second.py import first first.setX(88)
这样做才是正确姿势
原文:https://www.cnblogs.com/theda/p/15195391.html
评论(0)