Hi,
I recently read something saying that if you used from pymel.core import * that it was safe to use pyMel commands without using a prefix ( like py. or cmds.).
I did this and all seemed to work well until I moved the script into my Eclipse Project folder. I then noticed that Eclipse was complaining that it thought the commands were undeclaired variables ( see attached images).
Is there a way to make Eclipse recognize the commands without using a prefix while working in a pyDev project? Or, is it crazy to not use command prefixes ( despite the statement that it?s safe to do so).
Thanks!
I’m not sure about fixing your Eclipse problem. I use Vim which properly recognizes the commands.
The docs say that it is safe to import all, but having a namespace prefix makes it far far easier to search through your code. If you have a mixture of PyMEL, Maya Commands or math, path, OpenMaya or other modules, you can use the namespace to quickly distinguish everything. If you are copy/pasting functions from script-to-script, you know which modules you’ll need to import. If you are sharing code between people you don’t have to guess where a certain command is coming from.
If you find PyMEL is too slow and need to re-write using Maya Commands (as a contrived example) then you can quickly find “pm.” and re-write those lines.
I started out importing * too, but eventually realized it was better to have a namespace. Especially as your library of code grows.
Thanks for your thoughts. You make a good point about using namespaces to manage were the commands are coming from. Totally makes sense.
Cheers!
Never, ever use ‘from foo import *’. There’s no good reason whatsoever.