Alright, sounds like you're a new programmer. What you're seeing and working with right now is Python's
interactive interpreter. Essentially, this is a handy tool to use to test little pieces of code to see if they work, before incorporating them into a real program. Most Python teaching resources start with examples from the interactive interpreter, but you're absolutely right, they don't make it clear enough to new programmers that it isn't used for real programming.
In real programs, you would write all the code using a text editor (or an IDE, but save this for when you work on larger projects). If you are running Ubuntu, you already have gedit (the text editor you can find in the Applications menu). Gedit is nice because it has syntax highlighting for many languages, including Python. So you would write all of your code in gedit and save it just like any other document, and then you can run it from the command line. For example, to write a program that prints "Welcome to Python!" to the screen, first, you would open a text editor like gedit (and select Python for syntax highlighting), and then type in the print statement:
Code:
print "Welcome to Python!"
Then, save the file (you can use a .py extension for it to work in windows as well). Then, if you use your terminal to get into the directory where it was saved, you can
run the program with the command:
Code:
python [insert filename]
So if we called our little program "hello.py", we can run it with
Does this make sense to you?
Bookmarks