Top.Mail.Ru
Python
? ?
LiveJournal for python.
View:Personal Journal.
View:Friends.
View:Calendar.
Missed some entries? Then simply jump to the previous day or the next day.

Saturday, October 18th, 2008

Subject:to unicode from utf-8 back to utf-8 -- am I doing something pointless?
Time:2:34 pm.
In the following, does the conversion from UTF-8 bytes to Unicode and back again do anything useful other than validating the UTF-8?
import codecs
s = foo() #byte string
u = unicode(s, 'utf-8')
out = codecs.open('test.txt', 'w', 'utf-8')
out.write("%s\n" % u)
out.close()
If I'm fairly confident about the encoding, could I just as well say the following?
out = open('test.txt', 'w')
out.write("%s\n" % foo())
out.close()
Thanks!
Comments: Read 1 orAdd Your Own.

LiveJournal for python.

View:User Info.
View:Friends.
View:Calendar.
View:Memories.
Missed some entries? Then simply jump to the previous day or the next day.

Image