New submission from John Van Praag <j...@jvp247.com>:

The declaration errors='replace' works from within IDLE but not at the Windows 
command line. I am attaching a program and text file that demonstrate the 
problem. The error shows up at the Windows command line as follows:

C:\Users\John\Documents\Python\bug_reports\001>python -m read_my_file
aaaaaaa aaaaaaaaaaaaa aaaaaaaaaaaaaaa aaaaaaaaa

bbbbbbbbbbb bbbbbbbbbbbb bbbbbbbbbbbbbbbbbbb bbbbbbbbbbbb

Traceback (most recent call last):
  File "C:\Python31\lib\runpy.py", line 128, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "C:\Python31\lib\runpy.py", line 34, in _run_code
    exec(code, run_globals)
  File "C:\Users\John\Documents\Python\bug_reports\001\read_my_file.py", line 
20, in <module>
    readf()
  File "C:\Users\John\Documents\Python\bug_reports\001\read_my_file.py", line 
17, in readf
    print(line)
  File "C:\Python31\lib\encodings\cp437.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 10-11: 
character maps to <undefined>


NOTE: It appears I can only attach 1 file to this report. So I am copying the 
program here. The text file to read is attached.

'''
read_my_file.py:
Reads lines from faulty file.
Hangs at line 3 when run from Windows command line.
Platforms:
Windows Vista Ultimate 64-bit
Python 3.1.2
'''
#The file to read.
my_file = 'junk.txt'

def readf():
        #The declaration "errors='replace'" is suppposed replace characters the 
reader does not recognize with a dummy character such as a question mark.
        #This fix works in the interpreter, but not from the Windows command 
line.
        fh_read = open(my_file, errors='replace')
        for line in fh_read:
                print(line)

#Run.
readf()

----------
components: Windows
files: junk.txt
messages: 108987
nosy: jvanpraag
priority: normal
severity: normal
status: open
title: errors='replace' does not work at Windows command line
versions: Python 3.1
Added file: http://bugs.python.org/file17816/junk.txt

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue9126>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to