Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Christian Loveridge
seal-mask
.a{fill-rule:evenodd;}techdegree
Christian Loveridge
Python Web Development Techdegree Student 7,541 Points

Python getting input from Mac Terminal

When running Python scripts through my Mac terminal, as opposed to an IDE/Workspaces, it will not take input as typed--it requires me to make it a string with quotes:

Workspaces: Which direction? [right] Terminal: Which direction? ["right"]

I assume this is because it's trying to call it as a function, rather than accept it as an argument. Is there a way to bypass this?

Christian, you should not have to enter in the quotes. Python takes in all user input as a string. See this image on imgur http://i.imgur.com/1sFcXSP.png

Christian Loveridge
seal-mask
.a{fill-rule:evenodd;}techdegree
Christian Loveridge
Python Web Development Techdegree Student 7,541 Points

Exactly Derrick--That's why it was driving me nuts. Doing the quotes gets really old, really fast...This is what the no-quotes returns:

Accounting-2s-MBAir:testing Christian$ python lister.py
What do you want to add to the list? pizza
Traceback (most recent call last):
  File "lister.py", line 18, in <module>
    listit(str(input("What do you want to add to the list? ")))
  File "<string>", line 1, in <module>
NameError: name 'pizza' is not defined

I just figured it out after some heavy research--Python 2.X is the standard Python version on my Mac. Python 2 would not automatically parse input as strings (Relying on a deprecated function called "raw_input", which must be wrapped in eval() to input strings. Python 3 replaced that with input().

Because my Mac's python version was 2.7, it would not parse input as strings unless explicitly opened with python3, returning a Traceback error. Running scripts with python3 script_name.py makes it run exactly like in Workspaces!

Accounting-2s-MBAir:testing Christian$ python3 lister.py
What do you want to add to the list? Cheese
What do you want to add to the list?

Hope this helps someone else.

Christian, I use homebrew to manage my Python 2 and 3 installs. It leaves the system installed Python alone. I just had to update my path. This way I can keep both versions of Python up to date..