Python Tip: Escaping Strings to C-style encodings
Wai Yip Tung contributed a useful snippet in the Python Cookbook for escaping non printable characters in python to C-style equivalents. It uses an undocumented part of the standard python library. Very neat.
>>> a="ABC\nDEF"
>>> print a.encode('string_escape')
ABC\nDEF
>>>
About this entry
You’re currently reading “ Python Tip: Escaping Strings to C-style encodings ,” an entry on Chui's Counterpoint
- Published:
- 4.28.07 / 11pm
- Category:
- Python
No comments
Jump to comment form | comments rss [?] | trackback uri [?]