Running Python programs from the operating system shell

Switch to a console with your operating system's shell prompt and change to the new pyfund directory:

$ cd pyfund

We can execute our module simply by calling Python and passing the module's filename:

$ python3 words.py

The command would be as follows if on Mac or Linux:

> python words.py

When on Windows.

When you press Enter, after a short delay you'll be returned to the system prompt. Not very impressive, but if you got no response then the program is running as expected. If, on the other hand, you saw some error out, then something it wrong. An HTTPError, for example, indicates there's a network problem, whilst other types of errors probably mean you have mistyped the code.

Let's add another for-loop to the end of the program to print out one word per line. Add this code to the end of your Python file:

for word in story_words:
print(word)

If you go to your command prompt and execute the code again, you should see some output. Now we have the beginnings of a useful program!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset