Importing a module in interactive mode

Modules are text files containing Python code that's designed to be used inside another program. To work with a module, you need to import it. When you import the module, Python runs the module's code and stores the module's name in the namespace.

There are two ways to import modules: You can import the module name or you can import one or more of the names defined inside the module.

The following examples import the module tinymodule.py, which includes the following function:

def tinyfunction(x):

print "testing how modules and interactive mode communicate" print "You passed me the parameter", x z = x**2

print x, "squared is", z return z

Was this article helpful?

0 0

Post a comment