No worries - I hope I got that right.

It's a super useful pattern, because if you allow users to supply the import-strings, you don't have to care where the module is deployed. It's up to the user to make sure it's accessible via the PYTHONPATH, or what have you.

So - folks can update their code and add new behaviours without effort on your part.

D


On 21/05/13 21:48, Todd Widup wrote:
thanks Donal,  nice way of doing it :D


On Tue, May 21, 2013 at 10:43 AM, Donal McMullan <[email protected] <mailto:[email protected]>> wrote:


    if True:
        module_name_variable = "usermodules.todd"
    else:
        module_name_variable = "usermodules.jane"

    module = __import__(module_name_variable)
    instance = module.Klass()
    result = instance.prebuild()

    # Should have the same effect as:
    import usermodules.todd
    instance = usermodules.todd.Klass()
    result = instance.prebuild()


    I think you're correct to be wary of calling Python's eval:
    http://docs.python.org/2/library/functions.html#eval




    On 21/05/13 20:54, Todd Widup wrote:
    is there a python equivalent to eval?
    I am setting up a few things that could allow the user to specify
    a pre-build function but user A could specify a different
    prebuild function than user B, and I need some way of handling this.
    only thing I can think of right now is using
    maya.mel.eval("python string")
    which I really don't like the idea of doing that.
    any other ideas?


-- Todd Widup
    Creature TD / Technical Artist
    [email protected] <mailto:[email protected]>
    [email protected] <mailto:[email protected]>
    www.toddwidup.com <http://www.toddwidup.com>
-- 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]
    <mailto:[email protected]>.
    To post to this group, send email to
    [email protected]
    <mailto:[email protected]>.
    For more options, visit https://groups.google.com/groups/opt_out.




-- 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]
    <mailto:python_inside_maya%[email protected]>.
    To post to this group, send email to
    [email protected]
    <mailto:[email protected]>.
    For more options, visit https://groups.google.com/groups/opt_out.





--
Todd Widup
Creature TD / Technical Artist
[email protected] <mailto:[email protected]>
[email protected] <mailto:[email protected]>
www.toddwidup.com <http://www.toddwidup.com>
--
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 post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.




--

Donal McMullan
Production Engineer
 Desk: x6411
 Direct: +64 4380 3810
 Mobile: +64 2166 1254

--
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 post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to