Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #74010

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

From Dave Angel <davea@davea.name>
Subject Re: python33, windows, UnicodeEncodeError: 'charmap' codec can't encode characters in position, to print out the file contents to stdout,
Date 2014-07-06 08:57 -0400
Organization news.gmane.org
References <b447a73e-cad2-4448-abff-675a3b387e9b@googlegroups.com> <57444726-c79e-499c-aff6-5d268448035f@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.11538.1404651365.18130.python-list@python.org> (permalink)

Show all headers | View raw


gintare <g.statkute@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

python33, windows, UnicodeEncodeError: 'charmap' codec can't encode characters in position,  to print out the file contents to stdout, gintare <g.statkute@gmail.com> - 2014-07-06 01:45 -0700
  Re: python33, windows, UnicodeEncodeError: 'charmap' codec can't encode characters in position,  to print out the file contents to stdout, gintare <g.statkute@gmail.com> - 2014-07-06 02:05 -0700
    Re: python33, windows, UnicodeEncodeError: 'charmap' codec can't encode characters in position,  to print out the file contents to stdout, Dave Angel <davea@davea.name> - 2014-07-06 08:57 -0400
    Re: python33, windows, UnicodeEncodeError: 'charmap' codec can't encode characters in position,  to print out the file contents to stdout, Rick Johnson <rantingrickjohnson@gmail.com> - 2014-07-06 07:52 -0700
      Re: python33, windows, UnicodeEncodeError: 'charmap' codec can't encode characters in position,  to print out the file contents to stdout, Terry Reedy <tjreedy@udel.edu> - 2014-07-06 12:14 -0400
        Re: python33, windows, UnicodeEncodeError: 'charmap' codec can't encode characters in position,  to print out the file contents to stdout, Rick Johnson <rantingrickjohnson@gmail.com> - 2014-07-06 09:53 -0700
          Re: python33, windows, UnicodeEncodeError: 'charmap' codec can't encode characters in position,  to print out the file contents to stdout, wxjmfauth@gmail.com - 2014-07-06 11:14 -0700
            Re: python33, windows, UnicodeEncodeError: 'charmap' codec can't encode characters in position,  to print out the file contents to stdout, Rick Johnson <rantingrickjohnson@gmail.com> - 2014-07-06 12:37 -0700
              Re: python33, windows, UnicodeEncodeError: 'charmap' codec can't encode characters in position,  to print out the file contents to stdout, wxjmfauth@gmail.com - 2014-07-06 23:58 -0700

csiph-web