简体   繁体   中英

How to run my Python Linked List in the console or Mac Terminal?

I am following a data structures and algorithms course and we have made the basis of a Linked List. In the course, the guy interacts with the code using the console using the following commands:

>>python -i nameoffile.py
>>N1 = Node (10)
>>N1

Which then displays

 < Node data: 10>

However, when I have tried this using the PyCharm console and Pycharm terminal/Mac terminal I get the error::

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
              ^

This is the foundation of the linked list code I have been working with:

class Node:
    data = None
    next_data = None
def __init__(self, data):
    self.data = data

def __repr__(self):
    return ' < Node data: %s' % self.data

When I try running the code through the terminal, as one of the comments suggested, using:

>>python -i nameoffile.py
>>N1 = Node (10)
>>N1

I get this error:

>>> N1 = Node(10)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Node() takes no arguments

I have checked through everything and the filenames are correct but I am confused as to why this is happening. Any help, please?

I needed to use the Terminal with the given code. python -i nameoffile.py

In addition, to correcting the indentation. Thanks, StackOverflow!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM