I'm getting ready to start a job (in C#.NET) where having some Python experience is a plus. I did some reading about it a year or two ago, and picked up another book (Python 3 Object Oriented Programming by Dusty Phillips). I'm at the first code example, and having a really stupid issue.
I created my first class in a separate file, first_class.py. It's saved in my C:\Docs\Continuing Education\Object Oriented Python\Chapter 2 folder:
class MyFirstClass:
pass
He then says "run the command python -i first_class.py
". I open up the ?Python 3.5 Console? (if that is what it's called), and put that in there. I wasn't quite expecting it to work because it's executing from a different folder than the file is in.
I tried executing the command again, with the fully-qualified location of the file with and without quotes, but neither of those worked. Seeing a few other answers around, I tried all three (without the folder, and with and without quotes) but omitting the .py
extension, and that doesn't work. All of those commands so far have given the following error message with an error pointing to the end of the word "first_class":
SyntaxError: invalid syntax
I tried omitting the python
part of the command since I'm already in the Python program, but that doesn't work either.
Next, I found this answer and changed the "current directory" to the folder I listed above. Same deal with and without the python
and/or the .py
.
I tried using the import
function as well. That doesn't give any errors, so I thought it worked. I went on to the next command in the book:
>>>a = MyFirstClass()
Unfortunately, that gave the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>NameError: name 'MyFirstClass' is not defined
I'm sure I'm just missing something ridiculously simple. If this is a duplicate, by all means, flag away.