Sunday, November 16, 2014

Python Module: sys

Two very common and useful functions from module sys.

Case 1:  sys.path
if we want to load a module from a custom path instead of Maya default scripts directory

Example:
import sys

# add a new path to sys.path
# so Python will search the modules in the new path
# then you can import the module directly
sys.path.append('c:/test/testModule.py')

import testModule
Case 2: sys.modules
a dictionary mapping loaded modules and their names

Example:
# print out all modules and module names
for k,v in sys.modules.iteritems():
    print k, v

No comments:

Post a Comment