Mar-23-2024, 09:33 PM
Hi, I'm getting a "NameError: name 'name' is not defined" error when running my new test code. It's my first day of using Visual Studio Code with Python and the 'name' function (not entirely sure if you call 'name' a function..) has been working earlier but now, for some reason, it no longer seems to register.
This is my source code:
if name == 'Sam':
print('Hi Sam')
print('Are you good?')
and this is the output I get when I Run the code using the VSC extension 'Code Runner':
[Running] python3 -u "/Users/eric/Desktop/Python Programs test/if name == 'Sam':.py"
Traceback (most recent call last):
File "/Users/eric/Desktop/Python Programs test/if name == 'Sam':.py", line 1, in <module>
if name == 'Sam':
^^^^
NameError: name 'name' is not defined
[Done] exited with code=1 in 0.068 seconds
Sorry if my question is badly formulated or if I'm not posting this correctly, this is like I said my first day and also my first time ever posting in a coding forum. If you have pointers for me to correct please let me know, I'm all ears for feedback!
I'm using macOS Ventura version 13.6.1
Visual Studio Code version: 1.87.2 (Universal)
and Python 3.12.2
to point out just incase, I do believe I installed a version of Python a few years ago when I was trying to learn some coding but I'm not sure if that was on this same Mac or my old one. Not sure how to see if I have multiple versions of Python installed or not.
This is my source code:
if name == 'Sam':
print('Hi Sam')
print('Are you good?')
and this is the output I get when I Run the code using the VSC extension 'Code Runner':
[Running] python3 -u "/Users/eric/Desktop/Python Programs test/if name == 'Sam':.py"
Traceback (most recent call last):
File "/Users/eric/Desktop/Python Programs test/if name == 'Sam':.py", line 1, in <module>
if name == 'Sam':
^^^^
NameError: name 'name' is not defined
[Done] exited with code=1 in 0.068 seconds
Sorry if my question is badly formulated or if I'm not posting this correctly, this is like I said my first day and also my first time ever posting in a coding forum. If you have pointers for me to correct please let me know, I'm all ears for feedback!
I'm using macOS Ventura version 13.6.1
Visual Studio Code version: 1.87.2 (Universal)
and Python 3.12.2
to point out just incase, I do believe I installed a version of Python a few years ago when I was trying to learn some coding but I'm not sure if that was on this same Mac or my old one. Not sure how to see if I have multiple versions of Python installed or not.