On Monday, August 1, 2016 at 3:03:17 PM UTC-7, [email protected] wrote:
> k thanks Justin.
> 
> Also say theres a bunch of different modules in one folder. Do i need to 
> import each module individually.
> 
> Or is there a way to just import the folder and access the modules 
> individually in the script when theyre needed? 
> 
> thanks, 
> Sam

there's probably a variety of ways to do it.

import os

def moduleList(folder=None):

        modules = []

        folder = os.path.dirname(__file__) if folder is None else folder
        for (dirpath, dirnames, filenames) in os.walk(folder):
                
                modules += [f[:-3] for f in filenames if f.endswith(".py") and 
f != "__init__.py"]
                modules += [d for d in dirnames if 
os.path.exists(os.path.join(folder, d, "__init__.py"))]
                break

        return sorted(modules)


for moduleName in moduleList():
        __import__(moduleName, globals(), locals(), ["*"], -1)

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/0b5b76c6-b401-46b7-979a-0d99dd8a7c2d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to