iNTERFACEWARE Products Manual > Learning Center > Learning Python > Modules > Importing Modules |
|
Looking for Iguana v.5 or v.6? Learn More or see the Help Center.
To use a Python module in Chameleon, you must first ensure that its directory can be found by Chameleon's module search. See Searching for Modules for more details. After you have ensured that Chameleon can find your module, you need to import the module into your program. For example:
This code imports a module named temperature, and then calls the CtoF() function that is defined in this module. Note that the function call in the above example is temperature.CtoF(), not CtoF(). If you use import to import a module, you must include the module name when using any function or variable defined in the module. If you do not want to include the module name when calling a function, use from to import the function:
You can use from to import every function and variable in a module:
This makes it easier to use the functions and variables defined in a module, but also makes it easier to lose track of the module in which an imported function is defined. |