Just think of it like a directory structure.
If you import *, you are putting everything in your "current directory". If
you import with a namespace, everything is under a "new directory". The
only thing that changes is that leading namespace. Prefer the later and
"keep your directory clean" with a namespaced import.

Justin

On Tue, 24 Mar 2015 7:31 AM Marcus Ottosson <konstrukt...@gmail.com> wrote:

> Though Brian is right, it doesn’t quite explain why you are getting the
> behaviour you’re seeing.
>
> It’s a very good question, and I can completely understand why you would
> expect to prefix each PyMEL related call with pm as that is what you
> imported it as. The reason you don’t is a tad complicated, but has to do
> with two things.
>
>    - Scope
>    - Object Oriented Programming
>
> Scope has to do with what variable names you can call without referencing
> anything else.
>
> >>> my_variable = 5>>> print my_variable5
> >>> import os>>> print os
> <module 'os' from 'C:\Python27\lib\os.py'>
>
> The object-oriented part on the other hand is responsible for allowing you
> to call upon *members* of a variable; which in this case would instead be
> called an *object*.
>
> >>> my_variable = "hello"
> .>> print my_variable.upper()
> HELLO
>
> And that has to do with the dot following a variable. The dot is
> essentially saying “run the following command within the scope of the
> previous variable”. In this case, the variable is a string-object, and the
> string is an instance of a class with a method called upper() inside of
> it.
>
> # Looks something like this.class String:
>     def upper(self):
>         ...
>
> If you were to make your own class, you could do the same.
>
> class MyClass(object):
>     def __init__(self, value):
>         self.value = value
>
>     def plus_one(self):
>         return self.value + 1
>
> myobject = MyClass(5)print myobject.plus_one()# Which would print 6
>
> Objects returned by PyMEL works just like this, which is why you can call
> upon methods of those objects, without prefixing them with pm.
>
> Does that help?
> ​
>
> On 23 March 2015 at 18:14, <br...@meljunky.com> wrote:
>
>> Methods do no need to reference the module.
>>
>> pm.ls(type='camera')[0].getParent().getTranslation().z
>>
>> -brian
>> www.meljunky.com
>>
>>  -------- Original Message --------
>> Subject: [Maya-Python] Basic question about pyMel
>> From: Simon Davies <simonj.dav...@hotmail.co.uk>
>> Date: Mon, March 23, 2015 12:59 pm
>> To: python_inside_maya@googlegroups.com
>>
>> Hi all,
>>
>> I understand that if I import pyMel into Maya like this:
>>
>> from pymel.core import *
>>
>> I can then build up pyMel functions like this:
>>
>> ls(type='camera')[0].getParent().getTranslation().z
>>
>>
>> However if I import pyMel with a name space instead:
>>
>> import pymel.core as pm
>>
>> Would the pyMel methods above all need prefixing with pm like this?
>>
>> pm.ls(type='camera')[0].pm.getParent().pm.getTranslation().z
>>
>>
>> The above code doesn't work, so how should it be written if I import
>> pymel as pm?
>>
>> Thanks a lot.
>>
>> --
>> 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/33fcd70f-b4c2-496f-b05d-a41196a428ca%40googlegroups.com
>> <https://groups.google.com/d/msgid/python_inside_maya/33fcd70f-b4c2-496f-b05d-a41196a428ca%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 python_inside_maya+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/python_inside_maya/20150323111411.4b67a6573d13e8dd18091ea81788b1e6.4b8c60eefb.wbe%40email06.secureserver.net
>> <https://groups.google.com/d/msgid/python_inside_maya/20150323111411.4b67a6573d13e8dd18091ea81788b1e6.4b8c60eefb.wbe%40email06.secureserver.net?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> *Marcus Ottosson*
> konstrukt...@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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBtFFtW132_K_RQhYSe69rA%2BfkRhVgUbV_crq0Fho2Jug%40mail.gmail.com
> <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBtFFtW132_K_RQhYSe69rA%2BfkRhVgUbV_crq0Fho2Jug%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/CAPGFgA0AOT27OnZjJE4be5i1R67EqKCkd2a7ATgYQAEFdZQbqg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to