from pymel.core import * screwed up my module calls

19 views
Skip to first unread message

s...@weacceptyou.com

unread,
Aug 29, 2016, 4:05:01 PM8/29/16
to Python Programming for Autodesk Maya
Hello,

a while ago i made a post about my modules not being able to communicate when the call was nested in a different package.

I finally found the solution. It was because the module that was doing the call to the other module, had an import statement to pymel:

from pymel.core import *

i did this originally because i had a large script which constantly used pymel commands and didn't want to keep using the 'pm' namespace. But i guess this has allowed some name clashings? it was weird that it should stop my call to another module that was simply printing out something as a test.

my malfunctioning code was:
import samDev.rigging.TOPOCOAT.utility_functions.general as general
reload(general)
from pymel.core import *

general.test() #calling a function in general that printed out 'hello'
###############################

the error was always:
AttributeError: 'module' object has no attribute 'test'

---------------------------------
as soon as i removed the 'from pymel.core import *' it worked fine.. how the hell is 'general.test()' affected by pymel.core library?

thanks,
Sam

Eric Thivierge

unread,
Aug 29, 2016, 4:51:57 PM8/29/16
to python_in...@googlegroups.com
pymel has a pymel.core.general module that is getting imported with the * symbol import as `general`

Thus why its always advised NOT to use those types of imports.

--------------------------------------------
Eric Thivierge
http://www.ethivierge.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/728143f1-b191-4de8-8507-2afe0837b4c1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

s...@weacceptyou.com

unread,
Aug 29, 2016, 5:04:09 PM8/29/16
to Python Programming for Autodesk Maya
ok thanks, this had me confused for weeks.

thanks alot,
Sam

Alok Gandhi

unread,
Aug 29, 2016, 6:17:19 PM8/29/16
to python_in...@googlegroups.com
I would suggest NEVER to use import *, at all. It is one of those things that you should never do in python. There are certain idioms in python (like all other programming languages), and it is one of them. Why is it bad ? for the following reasons:
1. You will get things in your local namespace that you don't expect.
2. You will not know where certain names come from.
3. Your local names may be obscured by the imported module names.

Basically, this creates namespace pollution. So yea, NEVER do it.

For that matter, here are few good resources for things that you should and shouldn't do in python:


- Alok

Sam

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

For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages