from Art.Scripts import MyScript as myScript
myScript.Run()
module = __import__ ('Art/Scripts/%s' % Module)
getattr(module, 'Run')
--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/e8be73c8-5cb9-48ce-bb6e-d83e2e92fc44%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
How can I achieve this, when it's saying Import by filename is not supported. #
--
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 python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/e8be73c8-5cb9-48ce-bb6e-d83e2e92fc44%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
On Wed, Nov 30, 2016 at 2:17 PM I73 <wesley....@iugome.com> 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 PYTHONPATHIf 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":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 python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/e8be73c8-5cb9-48ce-bb6e-d83e2e92fc44%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/GDBq_xWNE-s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA24QLw4X3rCBmfiv-HoaUwkzVH7GNwDMJMNqOgddFPhVQ%40mail.gmail.com.
Hey Justin, I have appended the module path to the system python path under the ART directorysys.path.append( '%s' % os.environ['MAYA_TOOLS_REPO']) #tools repo is Art Directory 'C:/some_Directory''I am still getting that error if I use windows path string or dot path. I tried using imp to load the modules before I started this question, but it's still giving me errors: No module named Art.Scripts.myModule #
fp, pathname, description = imp.find_module('Art.Scripts.%s' % Module)
module = imp.load_module(name, fp, pathname, description)Trying to use the system path to load the modules seem a little confusing, since I don't think I can do that directly, everything I read online is either by direct path eg "C:/Some_dir/foo.py" and it also works if I use the entire path (Not the system path).
Am I able to do it with imp? Because It's returning me an IOError 'Using dot path and windows slash pathing':module = imp.load_source('myF**kingAnoyingModule', 'Art/Scripts/%s.py' % moduleName)
Also Thanks Alok Gandhi for helping!On Tue, Nov 29, 2016 at 6:17 PM, Justin Israel <justin...@gmail.com> wrote:
On Wed, Nov 30, 2016 at 2:17 PM I73 <wesley....@iugome.com> 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 PYTHONPATHIf 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":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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/e8be73c8-5cb9-48ce-bb6e-d83e2e92fc44%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/GDBq_xWNE-s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA24QLw4X3rCBmfiv-HoaUwkzVH7GNwDMJMNqOgddFPhVQ%40mail.gmail.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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAAD4CW469S0OiGdXKAwygg1nHLdi5tHDrHPryq5Yc4TiV1_dXw%40mail.gmail.com.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/e8be73c8-5cb9-48ce-bb6e-d83e2e92fc44%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/GDBq_xWNE-s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA24QLw4X3rCBmfiv-HoaUwkzVH7GNwDMJMNqOgddFPhVQ%40mail.gmail.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 python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAAD4CW469S0OiGdXKAwygg1nHLdi5tHDrHPryq5Yc4TiV1_dXw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/GDBq_xWNE-s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1ZB90bbDp8p%2Bu0g%3DPWXscN%2BNzBSZ-YxP0-aKsvfzTr%2BQ%40mail.gmail.com.
Yes, I am using __init__.py :)I did get it to work with using the direct path, Thank you!I was just really curious if I could have used the relative system path. Thanks for clearing this up!
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/e8be73c8-5cb9-48ce-bb6e-d83e2e92fc44%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/GDBq_xWNE-s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA24QLw4X3rCBmfiv-HoaUwkzVH7GNwDMJMNqOgddFPhVQ%40mail.gmail.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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAAD4CW469S0OiGdXKAwygg1nHLdi5tHDrHPryq5Yc4TiV1_dXw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/GDBq_xWNE-s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1ZB90bbDp8p%2Bu0g%3DPWXscN%2BNzBSZ-YxP0-aKsvfzTr%2BQ%40mail.gmail.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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAAD4CW4KrPzgTCnSVoktRLh-Vo7ej0VXkMA31uV86yh44xw7Kg%40mail.gmail.com.