Personal tools
You are here: Home CDAT Tips and Tricks Python Tips Modules in python.
Document Actions

Modules in python.

by Renata McCoy last modified 2007-05-08 10:48

Goal: Learn about modules in python.

 
To keep your programs manageable as they grow in size, you may want to break them up into several files. Python allows you to put multiple function definitions into a file and use them as a module that can be imported into other scripts and programs. These files must have a .py extension. For example:

# file my_function.py

def minmax(a,b):
if a <= b:
min, max = a, b
else:
min, max = b, a

return min, max

To use the above module in other programs, you would use the import statement.

import my_function

x,y = my_function.minmax(25, 6.3)


Powered by Plone