December 6, 2016 Leave a comment
Book ref: Project 4 (pg 84ff)
Python 2.7: Same
See also: Python 3/Project 4 post
You have started this new batch of tutorials working with the Python (Command Line) program. Python (Command Line) looks black and a bit ugly. It’s also a bit old fashioned in how it lets you interact with it.
It’s important to know about Python (Command Line) because it’s the easiest way to do something quickly in Python. For example, if I want to quickly check how something works in Python I will open up a Python command line and check it. So, you start out with it because it’s something you’re going to use for the rest of your Python programming days.
The command line has some limitations. Maybe the biggest of those is that it doesn’t let you save anything, but never fear! Python has an answer to that in IDLE. IDLE is a program that helps you write Python programs. One of the many things it can do is to allow you to save your programs to use them later. Open up your menu’s search bar and type “Python”. Click the entry that says IDLE(Python GUI). You should get a window that looks like this (the words might be different):
See how the title of the window says Python 3.4.5 Shell? It can do pretty much everything the Python (Command line) shell can do. However, that’s not where you can save your code! Instead, you need to open a new file. Click the “File->New File” menu item (or type Ctrl+N):
It’ll open up a new window like this:
Type your code in there:
and press Ctrl+S to save it. You’ll get a dialog box that asks you for a name to save it under. This is naming your Python file, much like you might name a word processing document or image that you create. In this case call it helloworld.py. When saving your code, add “.py” to the end of the file name. Finally, press F5. Pressing F5 is what runs your code.
In the Shell Window you’ll get something that says “== RESTART:” and some other guff. Then, after that, it’ll show you the output of the program you saved:
Hello world! >>>
Notice that IDLE gives different colors to different parts of your code? Try to work out what each of the colors means. IDLE has a lot of different features, project 4 of my book has more details, some of which are listed in the Python 3/Project 4 post.