By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,465 Members | 1,172 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,465 IT Pros & Developers. It's quick & easy.

singing the praises of unicode and codecs

P: n/a
I just wanted to thank Python for making encodings so easy!

I recently discovered that one of the tools I use stores everything in
UTF-8, and so I was getting some off-by-one errors because I was
treating things as strings. I added

def __unicode__(self):
return str(self).decode('utf-8')

to the base object in the hierarchy, and wrapped my popen calls with
readers and writers:

file_in, file_out, file_err = _os.popen3(self.command)
file_in = codecs.getwriter(self.encoding)(file_in)
file_out = codecs.getreader(self.encoding)(file_out)
file_err = codecs.getreader(self.encoding)(file_err)

and voilą! Everything works perfect!

Thank you Python!

Steve
Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.