Stefan Ram <r...@zedat.fu-berlin.de> wrote: > Chris Green <c...@isbd.net> writes: > >I have some text files which are ISO8859-1 encoded and I want to output > >them to screen using Python. > > Well, the first attempt would be: > > import pathlib > name = r"C:\example.txt" > encoding = r"iso8859-1" > path = pathlib.Path( name ) > with path.open( encoding=encoding, errors="ignore" )as file: > print( file.read() ) > > , but if you write to a console which needs a special encoding, > you might need: > > sys.stdout.buffer.write( file.read().encode( 'your screen encoding' )) > > (which is not always possible) instead of "print( file.read())", > and "import sys" at the start of the script. > Thanks! It's rather messy isn't it! :-)
I think I'll try converting the files before letting Python loose on them, iconv should manage that. -- Chris Green ยท -- https://mail.python.org/mailman/listinfo/python-list