Oh yes your right theres a typo node not attr... my bad tahts what you get when you devote 2 minutes per post. ![]()
And its just shorthand dint want to delve too deep into it just convert ist as close as possible to original code to demontsrate the point. The typo should be visible fi you go trough it. But tanks people would have missed it ![]()
however:
attributeExists( '', '') # returns None
is perfectly valid it python thinks none is same as 0 for compassions sake. Now since a failure is valid difference form 0 it also enables you to catch a bad input. But yes you have some point. Maybe it should throw a exception if the type is not string if it were to be truly pythonic?
CODE
def attributeExists(attr,node):
if type(node)!=type("") or type(attr)!=type(""): raise "not a valid name"
if (attr and node):
if not objExists(node): return 0
if attr in listAttr(node,shortNames=True): return 1
if attr in listAttr(node): return 1
return 0
but this is i admit being totally anal.
besides your coding style wihile okay an recommendable has a hole:
QUOTE
override many important commands, including file, eval, and help.
you can always call them trough super so its true:
help(help)
would use the cmds version of this but:
super.help(help)
would use pythons help so in way all i did was shorten the use of my code at the expense of internal coding prefix. So im saving out on code i use most at the expense of something i MIGHT decide to use.
however your right it does make the code hard to read, but thats a inherited problem of python itself. Bust yes still bad style admitted. Not that eval and help have much of use in a piece of good code. But file actually does.
Also note
QUOTE
compare that code to the mel code and you'll see why i do what i can to avoid writing mel.
yes but thats a bad comparasion since even the mel code could be written MUCH shorter. Ist jut thet maya coders are c++ coders so they tend to write code like that (and ist a big plus they can do it without overhead atleats you claim being python is big plus so its par here!)
now compare the following mel:
CODE
global proc int attributeExists(string $attr, string $node)
{
if ("" == $attr || "" == $node) return 0;
if( !objExists $node
) return 0;
for( $i in listAttr("-shortNames",$node)) if ($i==$attr) return 1;
for( $i in listAttr($node)) if ($i==$attr) return 1;
return 0;
}
which is the exact same thing but does have error raising is directly comparable to the python code in length and simplicity. And i made it more python looking.
Ergo almost no gain (well overall i do rate python more elegant). You just dont know mel half as good as you know python.
On the otherhand you need to manage your types in python.
PS. the board has a annoying habit of deleting spaces of first indent sometimes. Will mark as bug.
PPS. Again no claim that python is worse than mel but ist sure is not MUCH better either here. Because a python user needed to make this proc mel user didn't.