【发布时间】:2013-11-15 09:54:16
【问题描述】:
这是我的example.py 文件:
from myimport import *
def main():
myimport2 = myimport(10)
myimport2.myExample()
if __name__ == "__main__":
main()
这里是myimport.py 文件:
class myClass:
def __init__(self, number):
self.number = number
def myExample(self):
result = myExample2(self.number) - self.number
print(result)
def myExample2(num):
return num*num
当我运行example.py 文件时,出现以下错误:
NameError: global name 'myExample2' is not defined
我该如何解决这个问题?
【问题讨论】:
-
你需要
myExample2(self, num),然后将其称为self.myExample2()
标签: python class python-3.x module