导入功能有效,导入类没有

时间:2017-05-16 01:09:26

标签: python

当我导入一个函数时,它运行代码没问题,但如果我导入一个类它不起作用。它说ImportError:无法导入名称' Y'我已经在sublime文本和命令提示符上尝试过它。 如果我导入一个函数就可以了。

from testing2 import x
x()
#testing2.py has:
def x():
    print("It worked")

如果我导入一个类,它就不起作用。

from testing2 import Y
Y().x()

#testing2 has:

class Y:
    def x(self):
        print("It worked")

0 个答案:

没有答案
相关问题