Blender Python inserting text by script including Unicode symbols like degree symbol, and other Blender notes on problems which stumped me for a while and for which search engines were not helpful

I was using a Python script in Blender to dynamically alter a text mesh object. I could not for the life of me figure out how to put a degree symbol into the string. According to Blender/Python/Unicode searches (and many similar keyword combination) in Google, it should be possible to add \x0800 to add the Unicode degree symbol. However when I used this, inside double quotes to append to my string in the script, Blender would become unresponsive, take up 100% CPU for about 3 minutes and eventually display (in the terminal where I started it):

Exception RuntimeError: 'maximum recursion depth exceeded while calling a Python object' in <type 'exceptions.RuntimeError'> ignored
Error in sys.excepthook:
RuntimeError: maximum recursion depth exceeded

Original exception was:
Traceback (most recent call last):
  File "LineLabelScript", line 1, in <module>
RuntimeError: maximum recursion depth exceeded while calling a Python object

I also tried manually modifying the text object, going into Edit mode, using the Buttons window Char panel and finding the degree symbol there and inserting it, and then changing my code to, rather than replacing the whole old string with the new string, just trying to delete the whole old string except for the degree symbol, and update the dynamic parts of the string before and after that. However this approach also caused the above error.

Finally I found this page which showed a few special characters which can be inserted when a text mesh is selected and you're in Edit mode, specifically, Alt-G for the degree symbol.

So, although this didn't exactly fully solve my problem, (I needed to be able to add the degree symbol from my script, not manually going into Edit mode), I put in some good old fashioned debugging print statements, which printed the old manually-edited string with the degree symbol before trying to dynamically update it, and using the myOldString.split(" ") method, it printed in list format the different words in my string:

['other', '\xc2\xb0', "sections", 'of', 'my', 'string']

So, I have not looked yet as to which encoding this is or why this works but when I used \xc2\xb0 elsewhere in my code, it inserted the degree symbol as needed. But man was I stumped for a while on this one! Hope this helps somebody else!

Contact Martin with questions or comments.
All images and text is copyright © 2010 by Martin Muc