[issue30894] Python 3.6.1 String Literal Error Not Going to sys.stderr

2017-07-10 Thread George Gillan

New submission from George Gillan:

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 
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.

--
components: Interpreter Core
files: Python361_bug.txt
messages: 298083
nosy: George Gillan
priority: normal
severity: normal
status: open
title: Python 3.6.1 String Literal Error Not Going to sys.stderr
type: behavior
versions: Python 3.6
Added file: http://bugs.python.org/file47001/Python361_bug.txt

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30894] Python 3.6.1 String Literal Error Not Going to sys.stderr

2017-07-10 Thread Steven D'Aprano

Steven D'Aprano added the comment:

Before Python runs your code, it compiles it to byte-code. A SyntaxError means 
that the code cannot be compiled, and so it does not run.

So the SyntaxError is raised *before* any of the code runs, and standard error 
is not re-directed. This is expected behaviour, not a bug. You cannot catch 
compile-time errors at run-time.

--
nosy: +steven.daprano
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com