Foreign Character Problems In Python 2.5 and Tkinter

nickel_and_dime_2death at yahoo.com nickel_and_dime_2death at yahoo.com
Sat Oct 13 14:32:27 EDT 2007


On Oct 13, 5:22 pm, "Juha S." <jusa... at gmail.com> wrote:
> Thanks! Opening and saving the file with the iso-8859-1 codec seems to
> handle the characters correctly. Now the only problem left are the
> missing newlines in the output file. I tried googling for the iso code
> for newline and entering it in a Python string as '\x0A' but it doesn't
> work in the output file which still loses the newlines.
>
> Janne Tuukkanen wrote:
> > Sat, 13 Oct 2007 16:13:21 +0300, Juha S. kirjoitti:
>
> >> Thanks for the reply. I made changes to my code according to your
> >> example. Now any Scandinavian characters that are outputted by the
> >> program are missing in the Tk text box.
>
> >>             file = codecs.open(filename, 'r', 'utf-8', 'ignore')
>
> >  Remove that 'ignore'. If you then get error which complains,
> > that utf-8 codec can't handle the file, you've found the culprit.
> > The file might be in iso-8859-1.
>
> >    JanneT

As a noob I've struggled a bit, but basically what I've come up with
is => if the information is strings and especially strings stored in
any style of list/dict, it takes a loop to write the lines to file
myfile[ i ] + '\n' to keep each line for Python I/O purposes. If
you're done with Python manipulation and want WIN, MAC, or UNIX to
begin file I/O, then, you need the consideration of <newline-char>
from the os module, or code it in yourself, e.g. '\r\n'. The fact you
are using codec iso-latin-1 (or iso-8859-1) doesn't change the '\n'
from Python's viewpoint -- that is: '\n' is still '\n'. When your
efforts are I/O with binary encoding the data, it's all Python's
viewpoint.




More information about the Python-list mailing list