我不能使用主模块中其他模块中的函数
#MAIN FILE - mainfile.py
#Imports / display / pygame.init
from file2 import *
font=pygame.font.SysFont("Arial",35)
example(1) #THERE I DEFINE DE CLASS
Text=font.render(list1[0],0,(255,255,255))
win.blit(Text,(5,5))
#while loop
#file 2 - file2.py
class example:
def __init__(self, whichlist):
global list1
if whichlist==1:
list1=["bird", "bird2", "bird3"]
elif whichlist==2:
list1=["bird", "bird2", "bird3"]
#more code
在您的示例中,
function
可能比class
更好。与其使用global
,不如使用return
在
file2.py
在
file1.py
如果您真的需要使用类,那么您应该在类中创建使用
return
的方法对类使用
CamelCaseNames
也有一个很好的规则——它意味着Example
而不是“example”在
file2.py
在
file1.py
最终
相关问题 更多 >
编程相关推荐