12.07.2015 Views

Is Python a

Is Python a

Is Python a

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

AppendixAPPENDIXBBSolutions to End-of-Part Exercises 2Part I, Getting StartedSee “Part I Exercises” in Chapter 3 for the exercises.1. Interaction. Assuming <strong>Python</strong> s configured properly, the interaction should looksomething like the following (you can run this any way you like (in IDLE, from ashell prompt, and so on):% python...copyright information lines...>>> "Hello World!"'Hello World!'>>> # Use Ctrl-D or Ctrl-Z to exit, or close window2. Programs. Your code (i.e., module) file module1.py and the operating systemshell interactions should look like this:print 'Hello module world!'% python module1.pyHello module world!Again, feel free to run this other ways—by clicking the file’s icon, by usingIDLE’s Run ➝ Run Module menu option, and so on.3. Modules. The following interaction listing illustrates running a module file byimporting it:% python>>> import module1Hello module world!>>>Remember that you will need to reload the module to run it again without stoppingand restarting the interpreter. The question about moving the file to adifferent directory and importing it again is a trick question: if <strong>Python</strong> generatesa module1.pyc file in the original directory, it uses that when you import themodule, even if the source code (.py) file has been moved to a directory not in646

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!