Changes between Version 30 and Version 31 of UnicodeBranch
- Timestamp:
- Jul 12, 2007, 12:32:31 PM (17 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
UnicodeBranch
v30 v31 78 78 formal_name = u'%s %s %s' % (title, firstname, surname) # new version 79 79 }}} 80 This is useful for two reasons. Firstly, if the parameters contain non-ASCII characters, you won't have an exception raised. Secondly, if any of the parameters are objects, Python will automatica y call their {{{__unicode__}}} method and convert them to the right type. The "before" code would have resulted in the {{{__str__}}} method being called instead.80 This is useful for two reasons. Firstly, if the parameters contain non-ASCII characters, you won't have an exception raised. Secondly, if any of the parameters are objects, Python will automatically call their {{{__unicode__}}} method and convert them to the right type. The "before" code would have resulted in the {{{__str__}}} method being called instead. 81 81 Of course, this step is only a good idea if you are interpolating unicode strings. If your parameters are bytestrings, they will not automatically be decoded to unicode strings before being interpolated (Python cannot read your mind). Use {{{smart_unicode()}}} for that purpose. 82 82 * '''Warning for Python 2.3:''' There is a bug in the way Python 2.3 does string interpolation for unicode strings that you should be aware of if your code has to work with that version of Python. In the second line of code, above, if any of the parameters are non-basestring objects, Python will call the {{{__str__}}} method on the object, not the {{{__unicode__}}} method! So, for Python 2.3-compatible code, you would need to write something like