• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Getting errors trying to run programs in Python, can't find answers anywhere

Rest

All these years later I still chuckle at what a fucking moron that guy is.
Hf4HbWy.png

I get this error or a similar one no matter what I type once I've started python. I can't even change directories in python. "HelloWorld.py" is of course the name of a program in the folder "MyScripts," python will not run it or anything else in there. I don't know what's happening or why. I've unistalled and reinstalled python. The error is as follows:

File "<stdin>", line 1, in <module>
NameError: name 'HelloWorld' is not defined
 

EviLore

Expansive Ellipses
Staff Member
Congrats on starting to learn Python. Always show your source code when you're looking for help with debugging. It looks like you tried to call a variable named HelloWorld but didn't define it. Variables are assigned values with an = sign (see below). If you're trying to print "Hello World" you can just do

print("Hello World")

If you're trying to print a variable that contains the string "Hello World" you would do

hello_world = "Hello World"
print(hello_world)
 
Not sure if trolling but open up HelloWorld.py in Notepad, then type each line of code into the Python prompt you got (after typing python at the DOS prompt) to get a feel for how it works. Typing the name of a script directly into the interpreter is not how any of this works. I haven't touched Python in a very long time but I would guess "python HelloWorld.py" at the DOS command prompt (not within Python) probably runs the script.
 

StreetsofBeige

Gold Member
Off topic, but back in the mid 80s when stores would have C64s on demo my bro's and I would mess around with them. Looking back it was kind of weird because there would be a demo on, but no game or software playing. So kind of a pointless boring blue screen demo.

10 Print "Michael Jackson is the best"
20 goto 10
Run

Or another beauty.... 10 Print "You suck"
 

Rest

All these years later I still chuckle at what a fucking moron that guy is.
Not sure if trolling but open up HelloWorld.py in Notepad, then type each line of code into the Python prompt you got (after typing python at the DOS prompt) to get a feel for how it works. Typing the name of a script directly into the interpreter is not how any of this works. I haven't touched Python in a very long time but I would guess "python HelloWorld.py" at the DOS command prompt (not within Python) probably runs the script.
This is what it was, I forgot to include the "python" command.
 

Ionian

Member
Off topic, but back in the mid 80s when stores would have C64s on demo my bro's and I would mess around with them. Looking back it was kind of weird because there would be a demo on, but no game or software playing. So kind of a pointless boring blue screen demo.

10 Print "Michael Jackson is the best"
20 goto 10
Run

Or another beauty.... 10 Print "You suck"

Did the same. The staff copped on pretty quick but was hilarious as a kid.

Unfortunately a GOTO statement would eventually end so graduated to POKE statements and had the computers flashing colours in the border while a message scrolled across the screen. (Cheers Waz who did the POKE section for years for Zzap!64) :p.

Think it was a looping 'POKE 53280, X', X being the variable for colour code. Drove the salespeople mental. hahaha
 

Hari Seldon

Member
Yeah if you just type python at the command prompt you go into the interpreter itself. You usually never want to do this unless you are testing out something very short but even then I prefer to just make test scripts and run them rather than mess around in here.

One thing to note, especially when learning, is which version of python you are running. There is python 2.x and python 3.x, they are mostly compatible but have some issues, one of which is the format of the printing to the screen which can trip up people new to the language. Type: python --version at the cmd prompt to get the version. It is common to have both version 2 and version 3 installed simultaneously (e.g. OSX and some verisons of linux ship with python2 as the default python alias). In this case, running python scriptname.py will run the script in python 2.x. To run in python 3.x you would have to do: python3 scriptname.py
 
Top Bottom