Python Forum
Name error/is not defined - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Name error/is not defined (/thread-2860.html)



Name error/is not defined - foxtreat - Apr-15-2017

i just starter learning coding/programing,and after some joking around with bash i decided to learn python
i am making a script that should ask for your name and make a folder in the scripts directory using your name,however after imputing a name it just gives an error,
INFORMATION-i am using linux however i want my script to be cross-platform with windows aswell,python 3
here is my code


#!/usr/bin/env python
print "hello,i will automaticaly set up you account and files"
print "you will need to enter some data,be honest"
myname = input("What's your name?: ")
print (myname)
print "your name is" + (myname) 
print "okay,please wait while i set up your information"
import os 
os.mkdir((myname))
exit
i enter a name,lets say the name is da
i get this error
Error:
Traceback (most recent call last):   File "python.py", line 4, in <module>     myname = input("What's your name?: ")   File "<string>", line 1, in <module> NameError: name 'da' is not defined
i have tried alot of threads but nothing has worked
how do i make this error go away?


RE: Name error/is not defined - metulburr - Apr-15-2017

If you are using python2.x then its raw_input()


RE: Name error/is not defined - foxtreat - Apr-16-2017

i changed the code and it worked,i was sure i installed python 3,but when i checked i did infact have the wrong version,and i didn't even check correctly,sorry for the trubles


RE: Name error/is not defined - Ofnuts - Apr-16-2017

In Linux if you want to use Python v3 the name of the command is python3. The python command is always Python v2.


RE: Name error/is not defined - sparkz_alot - Apr-16-2017

As a "good practice",  it's best to put your 'imports' at the top of your script (after the shebang line)


RE: Name error/is not defined - metulburr - Apr-16-2017

(Apr-16-2017, 01:49 PM)Ofnuts Wrote: In Linux if you want to use Python v3 the name of the command is python3. The python command is always Python v2.

Not always. Like Arch Linux is a continuous release and python is python3.x, where you have to specify python2 to call python2.x.