This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author amaury.forgeotdarc
Recipients amaury.forgeotdarc, orsenthil, sven.siegmund, terry.reedy
Date 2008-08-18.16:16:00
SpamBayes Score 1.875961e-10
Marked as misclassified No
Message-id <1219076162.06.0.494791750327.issue2827@psf.upfronthosting.co.za>
In-reply-to
Content
I managed to get a proper traceback:

Exception in Tkinter callback
Traceback (most recent call last):
  File "c:\afa\python\py3k\lib\tkinter\__init__.py", line 1405, in __call__
    return self.func(*args)
  File "c:\afa\python\py3k\lib\idlelib\MultiCall.py", line 165, in handler
    r = l[i](event)
  File "c:\afa\python\py3k\lib\idlelib\ScriptBinding.py", line 124, in
run_module_event
    code = self.checksyntax(filename)
  File "c:\afa\python\py3k\lib\idlelib\ScriptBinding.py", line 86, in
checksyntax
    source = f.read()
  File "C:\afa\python\py3k\lib\io.py", line 1692, in read
    decoder.decode(self.buffer.read(), final=True))
  File "C:\afa\python\py3k\lib\io.py", line 1267, in decode
    output = self.decoder.decode(input, final=final)
  File "C:\afa\python\py3k\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position
34: character maps to <undefined>

This is because the file is opened in text mode, using the default
encoding (cp1252). It should instead open it in binary mode, and look
for a -*-coding-*- directive.
There is an attempt for this in linecache.py, but the logic there is wrong.

Is there already a function to properly open a python source file?
tokenize.detect_encoding could be used, but is there a way to open a
file in binary & universal mode?
History
Date User Action Args
2008-08-18 16:16:02amaury.forgeotdarcsetrecipients: + amaury.forgeotdarc, terry.reedy, orsenthil, sven.siegmund
2008-08-18 16:16:02amaury.forgeotdarcsetmessageid: <1219076162.06.0.494791750327.issue2827@psf.upfronthosting.co.za>
2008-08-18 16:16:01amaury.forgeotdarclinkissue2827 messages
2008-08-18 16:16:00amaury.forgeotdarccreate