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 George Gillan
Recipients George Gillan
Date 2017-07-10.21:07:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1499720846.63.0.81780429971.issue30894@psf.upfronthosting.co.za>
In-reply-to
Content
Python 3.6.1 String Literal Error Not Going to sys.stderr

Using Windows 7 and Python 3.6.1. Attempting to redirect sys.stderr to a file. The application will be deployed via .pyw file instead of .py so the GUI application runs without a console window.

Is this fixable or 'as-is' due to the nature of the way the interpreter scans the code?

The following code worked as intended.

#!/usr/bin/env python3.6 
errfile = 'test_err.txt'

import sys
errorlog = open(errfile, 'w')
sys.stderr = errorlog

1/0

The code above produced a file called test_err.txt with the following contents:

Traceback (most recent call last):
  File "C:\Users\George\Coding\Python\test\mintest.py", line 8, in <module>
    1/0
ZeroDivisionError: division by zero


The following code did not work as intended.

#!/usr/bin/env python3.6 
errfile = 'test_err.txt'

import sys
errorlog = open(errfile, 'w')
sys.stderr = errorlog

print("test)

The code above did not create the file test_err.txt with the error going to the console window instead.


Copy-paste from the Windows console.

The successful test (first) showed nothing in the console window; the error was logged to the file as noted above. The unsuccessful test (second) did not create the file, instead the error was sent to the console.

C:\Users\George\Coding\Python\test>mintest

C:\Users\George\Coding\Python\test>mintest
  File "C:\Users\George\Coding\Python\test\mintest.py", line 8
    print("test)
               ^
SyntaxError: EOL while scanning string literal

C:\Users\George\Coding\Python\test>

PS: This is my first bug/issue submission here. Please coach me as needed if I messed it up.
History
Date User Action Args
2017-07-10 21:07:26George Gillansetrecipients: + George Gillan
2017-07-10 21:07:26George Gillansetmessageid: <1499720846.63.0.81780429971.issue30894@psf.upfronthosting.co.za>
2017-07-10 21:07:26George Gillanlinkissue30894 messages
2017-07-10 21:07:26George Gillancreate