OK, so I’ve been working on Python frameworks for Maya for a couple of years.
I have a basic question, and it’s bugging me!
Why is the standard way to import cmds as follows:
import maya.cmds as cmds
Isn’t it more Pythonic to do this?:
from maya import cmds
Obviously, this is not a blocker for me, more of a technicality. Truth be told, I use pymel.core rather than cmds as it’s object based, but some commands only exist in cmds.
I doubt one way or the other would be considered more Pythonic. Maybe from maya import cmds, but nothing to lose sleep over.
The import maya.cmds as cmds idiom is what is used in most (all?) of the maya documentation, which could easily explain its popularity.
I tend to use both, and I’m not super disciplined about when I choose one or the other. But personally I prefer from maya import cmds because its easy to extend out as from maya import cmds, utils, mel, standalone if I need to pull in more from the maya namespace.
Yeah, the most correct answer, is the one that follows your teams local style guide.
If you’re the one creating the guide, go with what feels most readable to yourself and others.
One reason I’ve done import maya.cmds as mc in the past is so that I would get parity with the import pymel.core as pm .
I’ve also seen people do import pymel.core as pmc probably for similar reasons.
Currently our internal style guide prefers using the fully qualified path, so we do import maya.cmds while it feels almost silly to do it with such a common namespace in maya land, it keeps us stylistically in line with all our other python code.