On Wed, Nov 30, 2016 at 2:17 PM I73 <[email protected]> wrote:
> I am trying to import a module with the __import__ because I want to
> dynamically call a method from multiple modules this is the original import
> code:
>
> from Art.Scripts import MyScript as myScript
> myScript.Run()
>
> What I would like to do is something like this:
>
> module = __import__ ('Art/Scripts/%s' % Module)
> getattr(module, 'Run')
>
> How can I achieve this, when it's saying *Import by filename is not
> supported. #*
>
> Thanks guys!
>
The __import__() function expects you to use the same semantics as the
normal import keyword, where you are specifying a dot-style module path,
i.e. foo.bar.biz.baz. But it lets you do it like a function call with
strings. So you would be expected, in this case, to use a format like
"Art.Scripts.MyModule" and the "Art" location would need to be on the
PYTHONPATH
If what you actually want is to directly work with known absolute paths to
files, then you should be looking at the "imp" module, and specifically at
"imp.load_source":
https://docs.python.org/2/library/imp.html#imp.load_source
Justin
> --
> 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/e8be73c8-5cb9-48ce-bb6e-d83e2e92fc44%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/e8be73c8-5cb9-48ce-bb6e-d83e2e92fc44%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
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/CAPGFgA24QLw4X3rCBmfiv-HoaUwkzVH7GNwDMJMNqOgddFPhVQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.