Interaction. Assuming Python is configured properly, the interaction should look something like the following (you can run this any way you like (in IDLE, from a shell prompt, and so on):
...copyright information lines...>>>
"Hello World!"'Hello World!' >>> # Use Ctrl-D or Ctrl-Z to exit, or close window
Programs. Your code (i.e., module) file module1.py and the operating system shell 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 using IDLE’s Run→Run Module menu option, and so on.
Modules. The following interaction listing illustrates running a module file by importing it:
import module1Hello module world! >>>
Remember that you will need to reload the module to run it again without stopping and restarting the interpreter. The question about moving the file to a different directory and importing it again is a trick question: if Python generates a module1.pyc file in the original directory, it uses that when you import the module, even if the source code (.py) file has been moved to a directory not in Python’s search path. The .pyc file is written automatically if Python has access to the source file’s directory; it contains the compiled byte code version of a module. See Chapter 3 for more on ...