How do you write multiple lines of code and run it all at once in the interpreter? When i try to use the $ python filename.py method i get a syntax error. I was trying to do this while doing the simple def newLine(): print print "First Line." newLine() print "Second Line." which i wrote in a new window i know i can just hit run ? but isn't there a way to do it in the interpreter.
separate each individual statement with a semicolon ; print "First Line."; newline(); print "second line."
What was the syntax error? You should be able to run your python scripts that way.
the $ was the syntax error.
They probably meant it as the command-line prompt (meaning that what comes after it is something you'd type on the command line). Omit it from commands you try in the future and it should work.
Yeah the $ character is just the prompt string that shows up on UNIX-based systems.
when i take away the $ the syntax error changes to the filename.py
First, are you typing that command, "python filename.py" at the command prompt, and not the IDLE prompt? Second, are you using the actual filename of your script, and are you in the same directory where that file is? Third, post the message you're getting.
windows command prompt ?
When i use the $ in windows command prompt it says $ is not a known path or w/e
Yes. Don't type the $. In "Think Like a Computer Scientist" when he starts a line with "$" he means you should type the command at the command prompt. When he starts a line with ">>>" he means you type it in IDLE. Don't type the "$" or ">>>". Just use them as ways of distinguishing between operating system commands and python commands.
Join our real-time social learning platform and learn together with your friends!