On May 23, 2010, at 1:34 PM, ginodauri wrote:
> Hi
>
> I have one question.
> Code example
> Window().setLabel()# return label string
> but then i can't write something like this
> Window().setLabel().show()
>
> What is logic behind this,that this methods like setLabel return
> string type , and not instance?
the goal of methods is not to string them together infinitely.
consider this example with python's builtin list:
>>> l = ['one','two','three']
>>> l.sort().index('two')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'index'
the sort function does not return a new list instance, it returns nothing at
all. this is because it is modifying an existing object, not creating a new
one.
the proper way to do this is:
>>> l = ['one','two','three']
>>> l.sort()
>>> l.index('two')
2
the example you present is similar: like 'sort', 'setLabel' modifies the
Window in place, but it does not make a new window, so it should not return a
window instance. if anything, it should be returning None, instead of a string.
-chad
--
http://groups.google.com/group/python_inside_maya