Re: [Maya-Python] Stupid quick question about importing module from inside directory.

2016-12-01 Thread Justin Israel
On Fri, Dec 2, 2016 at 9:56 AM Wesley Keeling 
wrote:

> 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!
>

The path would be relative to your current working directory (os.curdir),
which means you would have to change it via os.chdir()
If you owned the process it would be fine, but maybe its not a good idea to
change the current directory from within a shared python environment like
maya, just for the purpose of importing a script.


>
> Thanks again guys!
>
> On Thu, Dec 1, 2016 at 12:42 PM, Justin Israel 
> wrote:
>
>
>
> On Fri, Dec 2, 2016 at 7:57 AM Wesley Keeling 
> 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 
> wrote:
>
>
>
> On Wed, Nov 30, 2016 at 2:17 PM I73  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
> 
> .
> 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

Re: [Maya-Python] Stupid quick question about importing module from inside directory.

2016-12-01 Thread Wesley Keeling
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!

Thanks again guys!

On Thu, Dec 1, 2016 at 12:42 PM, Justin Israel 
wrote:

>
>
> On Fri, Dec 2, 2016 at 7:57 AM Wesley Keeling 
> 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 
>> wrote:
>>
>>
>>
>> On Wed, Nov 30, 2016 at 2:17 PM I73  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
>> 
>> .
>> 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/pyth

Re: [Maya-Python] Stupid quick question about importing module from inside directory.

2016-12-01 Thread Justin Israel
On Fri, Dec 2, 2016 at 7:57 AM Wesley Keeling 
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 
> wrote:
>
>
>
> On Wed, Nov 30, 2016 at 2:17 PM I73  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
> 
> .
> 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
> 
> .
>
>
> 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

Re: [Maya-Python] Stupid quick question about importing module from inside directory.

2016-12-01 Thread Wesley Keeling
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 #*

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 
wrote:

>
>
> On Wed, Nov 30, 2016 at 2:17 PM I73  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
>> 
>> .
>> 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
> 
> .
>
> 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.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Stupid quick question about importing module from inside directory.

2016-11-29 Thread Justin Israel
On Wed, Nov 30, 2016 at 2:17 PM I73  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
> 
> .
> 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/CAPGFgA24QLw4X3rCBmfiv-HoaUwkzVH7GNwDMJMNqOgddFPhVQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Stupid quick question about importing module from inside directory.

2016-11-29 Thread Alok Gandhi
>
> How can I achieve this, when it's saying *Import by filename is not
> supported. #*
>
`imp.load_source` is what you need -
https://docs.python.org/2/library/imp.html#imp.load_source
Just a heads up, the `imp` module is deprecated in python 3.4 in favor of
`importlib`

On Wed, Nov 30, 2016 at 9:17 AM, I73  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!
>
> --
> 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
> 
> .
> 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/CAPaTLMQ7f4mCA-gc6r5%2B9uws8B2-kvA45E1UxpptFrwqKLsV_A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.