【发布时间】:2018-05-25 20:07:32
【问题描述】:
我正在尝试测试打包脚本并安装它们以备将来使用。我创建了一个脚本'my_script.py',然后安装它
python docs\setup.py develop 这似乎奏效了,因为我得到了所有成功的安装行。此代码包含以下内容:
class test(object):
def test_print(self, tool):
for i in tool:
print i
然后我创建了一个脚本,上面写着:
from my_script import test
tool = (1, 2, 3, 4, 5, 6)
test_print(self, tool)
它正在返回:
Traceback (most recent call last):
File "bin\test2.py", line 5, in <module>
test_print(self, tool)
NameError: name 'test_print' is not defined
我做错了什么?
【问题讨论】:
-
假设导入工作,它应该仍然是
test().test_print(tool)。test_print是类test的实例方法。你也没有通过self争论,它只在课堂上使用。
标签: python python-2.7 class package distribute