[Tutor] convert a file from plaintext(Ascii) to unicode? very quickquestions
kent37 at tds.net
Tue Aug 16 04:51:20 CEST 2005
I think Luke's suggestion will work if you use f.read() (to read the whole file as a single string) instead of f.readlines() and f.write() instead of writelines().
> 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:
>>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")
More information about the Tutor