iNTERFACEWARE Products Manual > Installing and Using Chameleon > Using Python Scripting > Using Python Scripts in Chameleon > Accessing the Top-Level Python Module |
|
Looking for Iguana v.5 or v.6? Learn More or see the Help Center.
Your Python scripts can access the top-level Python module that is included with Chameleon and Iguana. This module contains global variables such as field and environment. This top-level module is named __main__ (two underscore characters, followed by main, followed by two more underscore characters). To import from this module, use the import and from statements that you would normally use to import from an external module:
You should note that importing a variable from __main__ creates a new reference to the original. This means that assigning a value to the local variable does not change the value in __main__. To assign to the variable, you need to supply the module name:
This also means that if a variable is imported from __main__ and is later changed by a Chameleon script, the change is not made to your copy of the variable. For this reason, it is best not to import a variable if you want its value in your script to be synchronized with its value in __main__.
|