我正在学习一个数据结构和算法课程,我们已经建立了一个链接列表的基础。在本课程中,该人员使用以下命令使用控制台与代码进行交互:
>>python -i nameoffile.py
>>N1 = Node (10)
>>N1然后显示
< Node data: 10>但是,当我使用PyCharm控制台和Pycharm终端/Mac终端尝试这样做时,我会得到以下错误:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/code.py", line 63, in runsource
code = self.compile(source, filename, symbol)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/codeop.py", line 178, in __call__
return _maybe_compile(self.compiler, source, filename, symbol)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/codeop.py", line 106, in _maybe_compile
raise err1
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/codeop.py", line 93, in _maybe_compile
code1 = compiler(source + "\n", filename, symbol)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/codeop.py", line 143, in __call__
codeob = compile(source, filename, symbol, self.flags, True)
File "<input>", line 1
python -i LinkedListTest.py
^这是我一直在使用的链接列表代码的基础:
class Node:
data = None
next_data = None
def __init__(self, data):
self.data = data
def __repr__(self):
return ' < Node data: %s' % self.data当我尝试通过终端运行代码时,正如其中一个注释所建议的那样,使用:
>>python -i nameoffile.py
>>N1 = Node (10)
>>N1我知道这个错误:
>>> N1 = Node(10)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Node() takes no arguments我已经检查了所有的东西,文件名是正确的,但是我很困惑为什么会发生这种情况。有什么帮助吗?
发布于 2022-05-17 21:19:46
我需要在给定的代码中使用终端。python -i nameoffile.py
此外,还要纠正压痕。谢谢,StackOverflow!
https://stackoverflow.com/questions/72279147
复制相似问题