python33, windows, UnicodeEncodeError: 'charmap' codec can't encode characters in position, to print out the file contents to stdout,

Dave Angel davea at davea.name
Sun Jul 6 08:57:58 EDT 2014


gintare <g.statkute at gmail.com> Wrote in message:
> The answer is on page:https://docs.python.org/3.3/howto/unicode.html#reading-and-writing-unicode-data
> 
> The correct code:
> f=open('C:\Python33\Scripts\lang\langu\svtxt.txt','r', encoding='utf-8')
> linef=f.readlines()
> print(repr(linef))
> 

But naturally the path should be fixed as well. Either use forward
 slashes,  escape the backslashes,  or use a raw string.
 

f=open( r'C:\Python33\Scripts\lang\langu\svtxt.txt','r',
 encoding='utf-8')

-- 
DaveA




More information about the Python-list mailing list