Unicode strings

I can think of nothing else that has caused programmers more confusion than Unicode strings. I will not even attempt to explain the issues surrounding Unicode, but I feel it's important to bring up so when you see something like the following, you will be prepared.

>>> import pymel.core as pmc
>>> xform = pmc.polyCube()[0]
>>> myname = 'cubexform'
>>> xform.rename(myname)
>>> xform.name()
u'cubexform'

Unicode strings in Python 2 are prefixed with a u character. So how come even though we named our node using a "regular" (byte) string with no prefix, we got back a Unicode string from the xform.name() method?

Well, "regular" strings in Python 2 (the str type) support ASCII characters only. ASCII is able to represent a very limited number ...

Get Practical Maya Programming with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.