Skip to Main Content
Learning Python
book

Learning Python

by Mark Lutz, David Ascher
April 1999
Beginner content levelBeginner
384 pages
11h 15m
English
O'Reilly Media, Inc.
Content preview from Learning Python

Exercises

Okay: time to start doing a little coding on your own. This session is fairly simple, but a few of these questions hint at topics to come in later chapters. Remember, check Appendix C, for the answers; they sometimes contain supplemental information not discussed in the chapters. In other words, you should peek, even if you can manage to get all the answers on your own.

  1. Interaction. Start the Python command line, and type the expression: "Hello World!" (including the quotes). The string should be echoed back to you. The purpose of this exercise is to get your environment configured to run Python. You may need to add the path to the python executable to your PATH environment variable. Set it in your .cshrc or .kshrc file to make Python permanently available on Unix systems; use a setup.bat or autoexec.bat file on Windows.

  2. Programs. With the text editor of your choice, write a simple module file—a file containing the single statement: print 'Hello module world!'. Store this statement in a file named module1.py. Now, run this file by passing it to the Python interpreter program on the system shell’s command line.

  3. Modules. Next, start the Python command line and import the module you wrote in the prior exercise. Does your PYTHONPATH setting include the directory where the file is stored? Try moving the file to a different directory and importing it again; what happens? (Hint: is there still a file named module1.pyc in the original directory?)

  4. Scripts. If your platform supports ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Python

Learning Python

Fabrizio Romano
Getting Started with Python

Getting Started with Python

Fabrizio Romano, Benjamin Baka, Dusty Phillips

Publisher Resources

ISBN: 1565924649Supplemental ContentCatalog PageErrata