On Fri, Dec 2, 2016 at 7:57 AM Wesley Keeling <wesley.keel...@iugome.com>
wrote:

> Hey Justin, I have appended the module path to the system python path
> under the ART directory
>
> sys.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 #*
>

1) Does the 'Art' directory under C:/some_Directory contain a "__init__.py"
file?
2) Does the 'Scripts' directory under 'Art' contain a "__init__.py" file?
3) Is a file called 'myModule.py' located within the 'Scripts' directory?

If all of that is true, then you should be able to use the
'Art.Scripts.myModule' import path via the __import__() function


>
> 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).
>

This particular approach is just a lower level way of using the
__import__() function. It also requires the use of your PYTHONPATH to find
the module, or a path you provide. If you look at the docs for that
function it says you cannot pass a dot-named module. It needs to be the
actual module you want, and optionally a path to search for it. I don't
think this is what you want, since the suggestion was to either use the
__import__ approach if you want to use your PYTHONPATH and a standard
import path ("a.b.c"), or to use imp to load an absolute file 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)
>

This should be using the absolute path. Not a relative path.

fp = os.path.join(os.environ['MAYA_TOOLS_REPO'], 'Art/Scripts/%s.py' %
moduleName)
module = imp.load_source("myModuleName", fp)


>
>
> Also Thanks Alok Gandhi for helping!
>
>
>
> On Tue, Nov 29, 2016 at 6:17 PM, Justin Israel <justinisr...@gmail.com>
> wrote:
>
>
>
> On Wed, Nov 30, 2016 at 2:17 PM I73 <wesley.keel...@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
> 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 python_inside_maya+unsubscr...@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
> <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 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA24QLw4X3rCBmfiv-HoaUwkzVH7GNwDMJMNqOgddFPhVQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA24QLw4X3rCBmfiv-HoaUwkzVH7GNwDMJMNqOgddFPhVQ%40mail.gmail.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 python_inside_maya+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/CAAD4CW469S0OiGdXKAwygg1nHLdi5tHDrHPryq5Yc4TiV1_dXw%40mail.gmail.com
> <https://groups.google.com/d/msgid/python_inside_maya/CAAD4CW469S0OiGdXKAwygg1nHLdi5tHDrHPryq5Yc4TiV1_dXw%40mail.gmail.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 python_inside_maya+unsubscr...@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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to