• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

Ridiculous python problem

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

whiterabbit391

Registered
Joined
Aug 2, 2014
I've searched google, I've searched bing. Then I came here and read through 6 pages of archives, and I cannot find anybody who has this problem.

Super new to programming and Python.
Barely past " Hello World ! "

--------------------------------------------------

From what I understand, you can save a script in a text editor,
Then open it in the command line with the command

Python
filename.py
-----------------
and it should run that script.
In fact I think it did work for me earlier today with my simple programs. Very simple. Including the ole "Hello World!!"
which I saved as " hello.py "
Now when I type it in the command line it says

Traceback (most recent call list ):
file "<stdin>", line 1, in <module>
NameError: name 'hello' is not defined

???

Hopefully Stratus is around to help with this one.......:rain:
 
You probably did not suround hello in quotes. It thinks that 'hello' is a variable.

this will produce problems
Code:
#!/usr/bin/python

#A bad program

print(hello world)

This is the correct way

Code:
#!/usr/bin/python

print("Hello world")

And alternative using a variable

Code:
#!/usr/bin/python

hello = "hello world"
print(hello)
 
I can get it to print "Hello world!"

in the terminal with just
Code:
print "hello world ! "

but when I save the script of anything as a text,

it won't let me open it in the python terminal just by
typing

Code:
python
          filename.py

Which I "think" I did earlier in the day, and it worked. :-/
 

Attachments

  • mxb2.png
    mxb2.png
    16.7 KB · Views: 93
  • mxbterminal.png
    mxbterminal.png
    49.4 KB · Views: 96
To run your script, use this syntax from the command line.

Code:
[user@host~]# /path/to/python mxb.py

Not
Code:
 >>> mxb.py
while you're inside the interpreter.
 
ok. I figured out my big problem.

I was in the command line.
and typed python hit enter.
that opens python.
then I typed . mxb.py
and got the error.
after more searching I found that the first thing you type into the command line
is "python mxb.py"

not opening python in the CL first , then entering the filename.

thanks for your help guys.
hopefully the next kid that searches this problem on google will be directed here.
or does it have to be in the title of the thread??
?
 
ok. I figured out my big problem.

I was in the command line.
and typed python hit enter.
that opens python.
then I typed . mxb.py
and got the error.
after more searching I found that the first thing you type into the command line
is "python mxb.py"

not opening python in the CL first , then entering the filename.

thanks for your help guys.
hopefully the next kid that searches this problem on google will be directed here.
or does it have to be in the title of the thread??
?


pcgamer4life had mentioned this was your problem but perhaps it was not worded in a way you understood

As for google, it will search the conent of a thread but unless views and cross linking increase its unlikely this thread will be anywhere near the top. There are not enough tags for the spider(s) to place this within relevant searches ;)
 
Back