分离.py
class foo():
print 'a bunch of time consuming work'
class tryme():
print 'try me'*
主要.py
from separate import *
foo()
然而,它打印了两个:
a bunch of time consuming work
try me
最佳答案
当你调用 from separate import *
时
你执行打印命令!
如果你只想让一个实例做这样的事情:
class foo():
def my_print(self):
print 'a bunch of time consuming work'
并从 main 调用我的 print !
f = foo()
f.my_print
关于python - 我写了两个单独的文件,一个包含类,另一个调用它们,但调用一个是所有对象。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37937231/