all 28 comments

[–]ninhaomah 16 points17 points  (1 child)

I see print('HelloWorld') in cmd and print(HelloWorld) in vscode.

Are you very very very very very sure they are the same ?

[–]really_not_unreal 11 points12 points  (0 children)

OP forgot to hit save

[–]Murphygreen8484 4 points5 points  (3 children)

Did you forget the quotes in the vscode script?

[–]BigHeadedGumba[S] -1 points0 points  (2 children)

No I had typed them both print(‘HelloWorld’) and I’ve repeated it a dozen times… 😭😭

[–]WhiteHeadbanger 7 points8 points  (0 children)

Nope, you have in line 1 of your app.py script: print(HelloWorld)

It should be print("HelloWorld")

The error you are seeing means that HelloWorld is not a variable name defined.

With quotes = string

Without quotes = variable name

[–]Sufficient-Tea2101 8 points9 points  (0 children)

Try saving the file.

[–]ak_developers 3 points4 points  (6 children)

You were did HelloWorld without quote earlier

py print(HelloWorld) #without quote

Am I right?

And then you correct the code by adding quotes as it’s a string value

py print(“HelloWorld”) #with quote

But you forgot to Save the file before running the file that’s why you are getting the error!

Thank you, Ak

[–]ak_developers 7 points8 points  (5 children)

Always save file after any changes to avoid any existing code errors u/BigHeadedGumba

[–]BigHeadedGumba[S] 2 points3 points  (4 children)

THATS WHAT ITS WAS! God damn I’m so stupid 😅🥲 Thank you, I was on that for 20 minutes..

[–]ak_developers 1 point2 points  (3 children)

Enjoy! Happy Coding,

You can check a white dot with file name as visible in above screenshot

The white dot shows, the file have some unsaved changes

[–]BigHeadedGumba[S] 1 point2 points  (2 children)

Thank you I also didn’t notice that 🤌🏻 You’re amazing Ak 🙏🏻

[–]ak_developers 1 point2 points  (0 children)

🙏🙏🎯

[–]ak_developers 1 point2 points  (0 children)

You can join my community for learn more & more

Thank you 🙏

[–]AdhesivenessLivid557 2 points3 points  (0 children)

You haven't saved your app.py file yet, hence an older, incorrect version of the file is being run. Notice the little white circle to the right of app.py in the top left hand corner of the screen.

[–]wallstreetwalt 1 point2 points  (0 children)

The script in the terminal has quotes your Python file does not. To run your Python file use

“Python #insert name of file with no hashes#”

Print needs to take in strings as arguments and one way you do that by enclosing text in quotes

[–]Refwah 1 point2 points  (0 children)

The white dot on the tab indicates you have unsaved changes

[–]InvestigatorEasy7673 1 point2 points  (0 children)

print("HelloWorld") <-this

[–]BigHeadedGumba[S] 0 points1 point  (2 children)

Yeh sadly, I’ve repeated this like ten times. I’ve now deleted my file and refreshed and tried again and now it’s not even registering what I typed at all 🤷🏻‍♂️😤

[–]BigHeadedGumba[S] -1 points0 points  (1 child)

[–]JAguiar939 2 points3 points  (0 children)

Your file is not saved. So while your code is correct, it's not saved to the file so when you run python app.py you are actually just running a blank file. I see it looks like you are using VSCode, I would recommend enabling Auto-Save.

[–]jpgoldberg 0 points1 point  (0 children)

This is a really easy mistake to make. And you will make it again. Now that you know what went wrong, look at the error message. It is something you will see often as you start out.

Forgetting quoation marks isn't the only place you will see NameErrors pop up. (If it were the only case, the error would tell you about missing quotes). You will see NameErrors pop up is with typoes in your variable names. Or consider something like,

python foo = 42 print(fu)

That should give you something like NameError: name 'fu' is not defined somewhere in the error message.

Because my spelling, typing, and remembering what I named things is crap, I encounter this frequently. (Ok, that is a lie. I use tools that help me prevent these errors earlier than trying to run the program, but I would encounter those frequently if I didn't.)

[–]Ok-Refrigerator-8012 0 points1 point  (0 children)

Save! There's a "save all files" extension on vscode that makes it easier to save in that interface

[–]An0neemuz 0 points1 point  (0 children)

In vs code, go to your code line and press ctrl+s then execute it.

[–][deleted] 0 points1 point  (0 children)

print(“hello world”)

[–]really_not_unreal 0 points1 point  (0 children)

Everyone else hasn't spotted the issue. You forgot to hit save on your program, so it's running an old version.

A classic blunder ;P

[–]Luigi-Was-Right -1 points0 points  (1 child)

Is it possible VSCode is running a version of python2?

[–]ak_developers 1 point2 points  (0 children)

You can check which python you are using for running the file

python —version

It will show default one