Python Forum
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Name error/is not defined
#1
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?
Reply
#2
If you are using python2.x then its raw_input()
Recommended Tutorials:
Reply
#3
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
Reply
#4
In Linux if you want to use Python v3 the name of the command is python3. The python command is always Python v2.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#5
As a "good practice",  it's best to put your 'imports' at the top of your script (after the shebang line)
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#6
(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.
Recommended Tutorials:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 512 Nov-23-2023, 02:53 PM
Last Post: rob101
  [variable] is not defined error arises despite variable being defined TheTypicalDoge 4 2,042 Apr-05-2022, 04:55 AM
Last Post: deanhystad
  Error 'Contour' not Defined DaveG 3 2,283 Mar-13-2022, 03:29 AM
Last Post: deanhystad
  Getting "name 'get_weather' is not defined error and no json_data returned? trthskr4 6 3,528 Sep-14-2021, 09:55 AM
Last Post: trthskr4
  Error when refering to class defined in 'main' in an imported module HeRo 2 2,331 Apr-13-2021, 07:22 PM
Last Post: HeRo
  Why does lambda throw 'name value_o is not defined' error? karabakh 3 2,121 Dec-14-2020, 05:45 PM
Last Post: karabakh
  name error "name"is not defined MaartenRo 1 3,375 Jul-28-2020, 02:39 AM
Last Post: bowlofred
  Name Error: name 'Stockton' is not defined Pinokchu 3 2,234 Jun-13-2020, 02:48 PM
Last Post: Yoriz
  python library not defined in user defined function johnEmScott 2 3,769 May-30-2020, 04:14 AM
Last Post: DT2000
  error ,,name append is not defined'' Killdoz 1 4,982 May-24-2020, 06:23 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020