【发布时间】:2019-03-27 10:49:16
【问题描述】:
编译时出现此错误:
Traceback (most recent call last):
File "c:/Users/dvdpd/Desktop/ProjectStage/Main.py", line 1, in <module>
class Main:
File "c:/Users/dvdpd/Desktop/ProjectStage/Main.py", line 6, in Main
test = Reading()
NameError: name 'Reading' is not defined
代码:
class Main:
print("Welcome.\n\n")
test = Reading()
print(test.openFile)
class Reading:
def __init__(self):
pass
def openFile(self):
f = open('c:/Users/dvdpd/Desktop/Example.txt')
print(f.readline())
f.close()
我不能使用 Reading 类,我不知道为什么。
Main 和 Reading 在同一个文件中,所以我认为我不需要 import。
【问题讨论】:
-
编辑:谢谢大家,抱歉这个愚蠢的问题!
-
您也可以将问题标记为已删除。
标签: python python-3.x nameerror