导入模块:
print(‘from the spam.py‘) money=1000 def read1(): print(‘spam->read1->money‘,1000) def read2(): print(‘spam->read2 calling read‘) read1() def change(): global money money=0
spam.py
调用spam.py
money = 9999999 import spam #from the spam.py #第一件事:创建名称空间,用来存放spam.py中定义的名字 #第二件事:基于刚刚创建的名称空间来执行spam.py #第三件事:创建名字spam指向该名称空间,spam.名字的操作,都是以spam.py为准 print(spam.money) #1000 spam.read1() # spam->read1->money 1000 def read1(): print(‘test read1‘) spam.read2() #spam->read2 calling read spam->read1->money 1000 spam.change() print(spam.money)
test.py
时间: 2024-10-08 07:53:48