>
> Paul:
> Thanks for the explanation of the 2 representations - I like to try to
> understand what's going on under the hood when I do something.
> I have been beating this code to death to figure out what is going on.
> It appears that the str representation is not equivalent to a string
> (not that it should be):
>
>
Hmm... perhaps I'm misunderstanding what you're trying to say, but it seems
like maybe you're still misunderstanding the way str (or possibly print?)
works.

The 'str representation' IS equivalent to a string - because it is a string.

ie, if you do

type(str(anything))

you should get

<type 'str'>

...ie, what str() returns is always a string.

To explain what I said about 'print something' being equivalent to 'print
str(something)', perhaps it would be helpful to think of print as a
function, that under the hood does something like this:

print(*args):
    for arg in args:
        strRepresentation = str(arg)
        displayOnScreen(strRepresentation)

So, to explain your example:


> print tmpJnts
> #[nt.Joint(u'joint1'), nt.Joint(u'joint2'), nt.Joint(u'joint3')]
> print tmpJnts[0]
> #joint1
>

This gives 'joint1' because str(tempJnts[0]) is called behind the scenes...
resulting in 'joint1'.  However, despite this, it is still important to
remember that tmpJnts[0] is still actually a PyNode object, NOT a string.
 Doing print doesn't convert it over to a string permanently - it just uses
the string version for
printing.


> print len(tmpJnts[0]) # Error - object of type 'Joint' has no len()
>

This errors because, as I said, tmpJnts[0] is still a PyNode object, not a
string, and has no len().


> print str(tmpJnts[0])
> #joint1
>

This gives the exact same result as above, since print internally does str()
anyway...


> print len(str(tmpJnts[0]))
> #6
>
>
This now works because we are now taking the length of a string, which
supports len().

Basically, the fundamental concept here is that a PyNode object, and it's
string representation, are two different things, and are used in different
ways...

- Paul

-- 
http://groups.google.com/group/python_inside_maya

Reply via email to