Chapter 15. Modules. Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012. Modules. Nodules are the highest level program organization unit, which packages program codes and data for reuse Actually, each “file” is a module (Look into Lib in Python). Why Use Modules?.
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
Dr. Bernard Chen Ph.D.
University of Central Arkansas
(Look into Lib in Python)
>>> import math
>>> import random
>>> import module1 # assume this is the file name we saved
We will create two modules: module1 and module2
module2 will import data and functions from module1
print “First line of module1”
print “First line of module2”
module1.print_out(“Hello World!! ”) # Use module1’s function
print module1.x, module1.y # Reference module1’s variable
print x, y
If you try to import a module for the second time, Python will NOT execute it