Hey guys, I’ve been scripting in mel for quite a few years and have finally made the relieving switch to pymel in the past year. I’ve always imported the entire pymel namespace with from pymel.core import *. It feels a bit more intuitive to me than to have pm in front of everything, as I’ve seen some do.
Lately I’ve been wondering if that’s something I should be more paranoid about. So from some more experienced TA’s in the room, I’d like to know if you think this is a safe practice, and if not, why not? Is this something that’s ok to do in most cases, or do you feel it’s never ok?
I tend to not do that when I have a large tool/script that imports several libraries because of name clashing, and more importantly, it makes it harder to debug and maintain later on (and esp. by someone who is unfamiliar will all the libraries you are using)…
But if it’s just a tiny process that only uses pymel.core stuff…I tend to let it pass…
RobG yells at people for doing *. Just use a namespace and get used to it. It makes it abundantly clear where a command is coming from. Imagine this at the top of a py file.
from pymel.core import *
from secret.module import *
from something.else import *
parent(secret = True)
How can you tell where the “parent” command name is coming from? YOU CAN’T!!! IT’S CRAZY!! Is “parent” a maya command, a pymel command, or a command from those other modules?
It really bites you if you’re trying to learn pymel. Is this a maya command, a pymel command? For the longest time I thought, “redistribute” was an undocumented Maya UI command because we weren’t using namespaces.
The day you have to go through and fix someone elses code and they’ve imported * into the main name space is the day you stop importing *
I don’t mind as much on well documented libraries, or stuff like PyQt that prefaces it with a Q, but other stuff is infuriating.
Having to try and figure out where that particular function is coming from, or wondering how you managed to break your program by importing something else
++ to all of the above. In any case, pm…core.blah is functional - it’s tied in to autocomplete and code navigation if you use an IDE. If you do a lot of loose imports you end up having goofy personal prefixes in front of everything anyway, so you’re hardly saving typing: my_parent() is not much of a win over pm.core.parent.
The only time I use from pyme.core import * now, is when running mayapy in a sub process, because your entire environment gets initialized when having that import.