[Tutor] convert a file from plaintext(Ascii) to unicode? very quickquestions
rabidpoobear at gmail.com
Tue Aug 16 02:57:28 CEST 2005
Help on class unicode in module __builtin__:
[snip help stuff]
| S.encode([encoding[,errors]]) -> string or unicode
| Encodes S using the codec registered for encoding. encoding defaults
| to the default encoding. errors may be given to set a different
| handling scheme. Default is 'strict' meaning that encoding errors
| a UnicodeEncodeError. Other possible values are 'ignore', 'replace'
| 'xmlcharrefreplace' as well as any other name registered with
| codecs.register_error that can handle UnicodeEncodeErrors.
[snip rest of help]
I dont know much about Unicode but it seems like
f = file(filename, "r")
text = f.readlines()
text = text.encode()
#or maybe just text.encode()?
should encode the filetext to unicode.
then you could do a
f = file(filename, "w")
sorry I don't know more about it but I hope that helps you.
----- Original Message -----
From: "D. Hartley" <denise.hartley at gmail.com>
To: "Python tutor" <tutor at python.org>
Sent: Monday, August 15, 2005 7:49 PM
Subject: [Tutor] convert a file from plaintext(Ascii) to unicode? very
> Hello guys!
> Is there a way to convert a file from plaintext(Ascii) to unicode? I
> have found all my notes about moving between hex., int's, chr's,
> ord's, etc, but all of these things were only riddle exercises to me
> and I have a hard time keeping them straight. I'm pretty sure I knew
> the answer to this and now cannot find it anywhere (even googling
> through my old tutor posts!)
> Does anyone have a quick answer/pointer?
> Thanks so much!
> Tutor maillist - Tutor at python.org
More information about the Tutor