Preventing control characters from entering an XML file

Scott David Daniels scott.daniels at acm.org
Fri Jan 6 01:58:07 CET 2006


Frank Niessink wrote:
> Scott David Daniels wrote:
>> Frank Niessink wrote:
>>> - What is the easiest/most pythonic (preferably build-in) way of 
>>> checking a unicode string for control characters and weeding those 
>>> characters out?
>>      drop_controls = [None] * 0x20
>>      for c in '\t\r\n':
>>          drop_controls[c] = unichr(c)
>>      ...
>>      some_unicode_string = some_unicode_string.translate(drop_controls)
> 
> Your code gave me a "TypeError: an integer is required"....

Sorry about that.
 >>          drop_controls[c] = unichr(c)
should have been:
 >>          drop_controls[ord(c)] = unichr(c)

-- 
-Scott David Daniels
scott.daniels at acm.org



More information about the Python-list mailing list