> Alternatively just use:
>
> eval('myScript.'+functionArray[0])
that would work too, but only if his module loader adds the loaded module to
sys.modules, which, if it is using the __import__ function, it will not.
-chad
>
> On Nov 24, 3:09 pm, Chad Dombrova <[email protected]> wrote:
>> here's a simple method:
>>
>> import pydoc
>> for f in functionArray =
>> ['modulename.saySomething','package.modulename.saySomethingElse']:
>> func = pydoc.locate(f)
>> func()
>>
>> the name that you pass to pydoc.locate should be the full dotted path to the
>> function (including the module name). the module must be on sys.path.
>>
>> if, in your example, myscript is a module *object* and not just a module
>> *name*, then this should also work:
>>
>> myscript = sourceScript.importPath("Z:/python/myScript.py")
>> for f in functionArray = ['saySomething','saySomethingElse']:
>> func = getattr(myscript, f)
>> func()
>>
>> -chad
>>
>> On Nov 24, 2009, at 6:50 AM, Daniel wrote:
>>
>>> Hello,
>>
>>> is there a way to append a string that represents a function to a
>>> module and then evaluate the whole thing? i got a python importer
>>> class that sets the pythonPath for the specified script and returns
>>> the name of the module like so.
>>
>>> myscript = sourceScript.importPath("Z:/python/myScript.py")
>>
>>> Now if i call myScript.saySomething() by hand it can execute the
>>> function in myScript. The problem is: i have an array representing all
>>> the functions that i want to map to a menu like so: functionArray =
>>> (['saySomething()','saySomethingElse()']) . is there a way to cast a
>>> string to a function like
>>
>>> myscript.(castToFunctionType)functionArray[0]
>>
>>> similar to str(3)?
>>
>>> thanks...
>>
>>> --
>>> http://groups.google.com/group/python_inside_maya
>>
>>
>
> --
> http://groups.google.com/group/python_inside_maya
--
http://groups.google.com/group/python_inside_maya