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 Python Basics (Retired) Ins & Outs String Concatenation

File "<stdin>", line 1 error when running script

After I type the script and go to the console to run the script I get this error:

python lumberjack.py File "<stdin>", line 1 python lumberjack.py ^ syntaxError: invalid syntax

This is my code:

name = input("What's your name? ")

if name == "Irfan": print(name + " is a lumberjack and he's okay!") else: print(name + "sleeps all night and " + name + " works all day!")

5 Answers

Hmm i ran your code in the workspace and It ran fine... Try just typing

python lumberjack.py

also check that you have saved your file and that your filename is in fact lumberjack.py

I had this problem as well, then I realized I was still in the python interpreter.
I typed:

exit()

then at the workspace prompt:

python lumberjack.py

and it worked properly.

Same for me, also got it when I tried opening python on a separate line from opening the file.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Danielle Abelard so was your problem the same as johnmatulich? You were trying to run a Python script from inside the Python shell?

Wow, thank you! I get it now. I need to get out of the python shell first to run a script!

Hm, I reopened the workspace and it worked fine this time. Must just be some bug with the workspace because before I had it saved too and typed the same thing you told me to but it gave that error before. Thanks!

Hello! Just my 0.02$: I tried meddling around with the default indentation, and anything besides Spaces 2 seems to lead to the <stdin> syntax error.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

So long as the spacing is consistent, Python doesn't care the number of spaces.

Kevin McFarland
Kevin McFarland
5,122 Points

I also had errors... I stumpled upon "Check Module" under the Run menu and it showed an indentation error. I'm also using the Python 3.4.2 script editor.