[Tutor] convert a file from plaintext(Ascii) to unicode? very quickquestions
rabidpoobear at gmail.com
Tue Aug 16 03:51:02 CEST 2005
I'm forwarding this private message(hope you don't mind Denise)
I personally have no idea what to do, but
someone else might be able to help.
----- Forwarded Message -----
text is a list, so you can't encode it. but you can iterate over each
of the elements and encode them. I have tried several variations of
that, but keep ending up with all my newlines being little boxes. any
On 8/15/05, luke <rabidpoobear at gmail.com> wrote:
> >>> help(unicode)
> Help on class unicode in module __builtin__:
> [snip help stuff]
> | encode(...)
> | S.encode([encoding[,errors]]) -> string or unicode
> | Encodes S using the codec registered for encoding. encoding
> | 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',
> | '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!
> > ~Denise
> > _______________________________________________
> > Tutor maillist - Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> Tutor maillist - Tutor at python.org
More information about the Tutor