Python Python Basics (2015) Logic in Python Fully Functional

Cannot run script (syntax error) despite saving it

https://w.trhou.se/c5g189ib6n

I even tried exiting out of workspaces and going back in. Went into python. Then typed the file name 'python functions.py'

This is the error that I get (the arrow is pointing at the 's'):

File "<stdin>", line 1
python functions.py
^
SyntaxError: invalid syntax

2 Answers

Alex Koumparos
MOD
Alex Koumparos
Python Web Development Treehouse Moderator 32,030 Points

Hi Peter,

If you're already in the Python interpreter, you don't type python functions.py (at least not in modern python) to execute your script. Type import functions (don't include the .py)

To run the script from the command line (i.e., in Bash, not in Python) you would type python functions.py.

Cheers

Alex

PS: A side note of caution: against the recommendations of PEP 394, the Treehouse workspaces launch python3 when typing python. That probably won't be the case in other systems you use. It's more likely that other systems will follow PEP 394 and launch python2 when you type python, and to load python 3 you have to explicitly type python3

OK that worked!

It's strange that I have to use the import function now because in the past (a few days ago) I would type in 'python filename.py' and it would run the script.

Thanks again for your help.

Alex Koumparos
MOD
Alex Koumparos
Python Web Development Treehouse Moderator 32,030 Points

Hi Peter,

Your problem is that function definition only accepts one argument (name) but you are passing in two (and your print statement is assuming you have two: name and pronoun).

You need to add the second argument to your function definition.

Also, when you call your function, you don't have enough quotes. You have opening and closing quotes around the name argument, but only closing quotes around the pronoun argument.

Cheers

Alex

Thanks for responding, Alex. Despite the errors you mentioned, I did not receive any errors related to the script itself, but the script name when I tried to get it to run. Please take a look at my original post for the SyntaxError that I get.

Here's my updated script based on your corrections, but still get the same error: https://w.trhou.se/c5g189ib6n

Thanks again.