Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
User input question
#1
Bare with me, coding is completely out of my wheelhouse! I'm working through a book called "Python Crash Course". I'm trying to work with a really simple program that should accept user input. It isn't working in the text editor (Sublime Text)which makes sense I guess. But when I try to run the code from the command line I get the error below. This confuses me because obviously the program is getting my input. I apologize if its something really simple, I'm really new to Python. I should also mention that I can get the program to work with Idle but I'd really like to continue using Sublime Text if possible.

name = input("Please enter your name: ")
print("Hello, " + name + "!")
Output:
Please enter your name: Chris
Error:
Traceback (most recent call last): File "greeter.py", line 2, in <module> name = input("Please enter your name: ") File "<string>", line 1, in <module> NameError: name 'Chris' is not defined
Reply
#2
Please, read
https://python-forum.io/Thread-Basic-Pyt...-raw-input

By the way, it's bit confusing that you claim it works in IDLE. Do you have more than one python installations?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(Jul-10-2018, 03:57 AM)buran Wrote: Please, read
https://python-forum.io/Thread-Basic-Pyt...-raw-input

By the way, it's bit confusing that you claim it works in IDLE. Do you have more than one python installations?

After reading your link I'm going to check to verify what version of Python I'm using. The program does work when I run it in IDLE, I don't think I have more than one installation but I'll double check.
Reply
#4
Mystery solved...When trying to run the program from the command line in Mac I was entering:
python <file name> when I should have been entering python3 <file name>. Changing that command fixed it for me.

However, when I enter python --version from my terminal I get back 2.7.10 even though I just upgraded to 3.7.0...
Reply
#5
(Jul-11-2018, 03:43 AM)linuxnoob Wrote: However, when I enter python --version from my terminal I get back 2.7.10 even though I just upgraded to 3.7.0...

Try python3 --version.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#6
You have 2 python installations. On Mac it comes with python2 pre-installed. With python you invoke python2, with python3, well you invoke python3
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
(Jul-11-2018, 03:43 AM)linuxnoob Wrote: Mac I was entering:
Doing it Right Mac

Alternative pyenv(Simple Python Version Management) also work on Mac.
Example how it look on Linux:
# Update pyenv
mint@mint ~ $ pyenv update
 
# Look at what's available
mint@mint ~ $ pyenv install --list
Available versions:
....
3.6.6
  3.6.6rc1
  3.7.0
  3.7-dev
  3.8-dev
....
 
# Update needed
sudo apt-get update
sudo apt-get install libffi-dev
 
# install
mint@mint ~ $ pyenv install 3.7.0
Installing Python-3.7.0...
Installed Python-3.7.0 to /home/mint/.pyenv/versions/3.7.0
 
# Set python and pip to point to 3.7
mint@mint ~ $ pyenv global 3.7.0
mint@mint ~ $ python -V
Python 3.7.0
mint@mint ~ $ pip -V
pip 10.0.1 from /home/mint/.pyenv/versions/3.7.0/lib/python3.7/site-packages/pip (python 3.7)
mint@mint ~ $ 
# Finish
So now python and pip always point to what you set global in this case 3.7.
Reply
#8
(Jul-11-2018, 05:27 AM)buran Wrote: You have 2 python installations. On Mac it comes with python2 pre-installed. With python you invoke python2, with python3, well you invoke python3

Well now I feel a bit dumb! Should I remove python2?
Reply
#9
No, it's system Python and is required.
Read Doing it right Mac link from snippsat's post #7
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#10
(Jul-12-2018, 04:03 AM)buran Wrote: No, it's system Python and is required.
Read Doing it right Mac link from snippsat's post #7

I installed Python 3 before seeing this post unfortunately. Hopefully it will work well enough for me.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  WHILE LOOP NOT RETURNING USER INPUT AFTER ZerroDivisionError! HELP! ayodele_martins1 7 990 Oct-01-2023, 07:36 PM
Last Post: ayodele_martins1
  restrict user input to numerical values MCL169 2 869 Apr-08-2023, 05:40 PM
Last Post: MCL169
  user input values into list of lists tauros73 3 1,023 Dec-29-2022, 05:54 PM
Last Post: deanhystad
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,026 Dec-25-2022, 03:00 PM
Last Post: askfriends
Question Take user input and split files using 7z in python askfriends 2 1,027 Dec-11-2022, 07:39 PM
Last Post: snippsat
Sad how to validate user input from database johnconar 3 1,837 Sep-11-2022, 12:36 PM
Last Post: ndc85430
  How to split the input taken from user into a single character? mHosseinDS86 3 1,137 Aug-17-2022, 12:43 PM
Last Post: Pedroski55
  Use pexpect to send user input alisha17 0 1,826 May-10-2022, 02:44 AM
Last Post: alisha17
  WHILE Loop - constant variables NOT working with user input boundaries C0D3R 4 1,434 Apr-05-2022, 06:18 AM
Last Post: C0D3R
  input function question barryjo 12 2,634 Jan-18-2022, 12:11 AM
Last Post: barryjo

Forum Jump:

User Panel Messages

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