[issue23035] python -c: Line causing exception not shown for exceptions other than SyntaxErrors

2021-06-15 Thread Irit Katriel


Change by Irit Katriel :


--
type:  -> enhancement
versions: +Python 3.11 -Python 3.5

___
Python tracker 

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



[issue23035] python -c: Line causing exception not shown for exceptions other than SyntaxErrors

2014-12-12 Thread Arfrever Frehtes Taifersar Arahesis

Arfrever Frehtes Taifersar Arahesis added the comment:

Arguments after argument of -c option are included in sys.argv:

$ python -c "import sys; print(sys.argv)" a b
['-c', 'a', 'b']

--

___
Python tracker 

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



[issue23035] python -c: Line causing exception not shown for exceptions other than SyntaxErrors

2014-12-12 Thread Terry J. Reedy

Terry J. Reedy added the comment:

One can paste multiple lines, comprising multiple statements, into the console 
interprer.  (Shell only recognizes a single pasted statement.)  
I agree, however, that it seems that Python could keep the split version of the 
input line for the purpose of tracebacks.  I just tried

C:\Users\Terry>python -c "import sys; print(sys.argv)"
['-c']

I expected to see to see a list of 3 strings, not 1.

--

___
Python tracker 

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



[issue23035] python -c: Line causing exception not shown for exceptions other than SyntaxErrors

2014-12-12 Thread Arfrever Frehtes Taifersar Arahesis

Arfrever Frehtes Taifersar Arahesis added the comment:

Argument of -c option can have multiple lines, while only 1 line can be 
directly entered in interactive interpreter.

python -c $'line1\nline2\nline3\nline4\n...'

--

___
Python tracker 

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



[issue23035] python -c: Line causing exception not shown for exceptions other than SyntaxErrors

2014-12-12 Thread Terry J. Reedy

Terry J. Reedy added the comment:

Code entered with -c seems to be treated the same as code entered at the >>> 
prompt of the interactive interpreter.

>>> 1/0
Traceback (most recent call last):
  File "", line 1, in 
ZeroDivisionError: division by zero

In both cases, the offending code is right there to be seen, so I can 
understand reluctance to echo it.  For SyntaxErrors (and only them) echoing the 
code is needed to have something to point to.

Idle's Shell does what you want.
>>> 1/0
Traceback (most recent call last):
  File "", line 1, in 
1/0
ZeroDivisionError: division by zero

Shell can do this because it has easy, platform-independent access to the 
tkinter Text widget storing and displaying previously entered code.  I presume 
accessing a system-dependent console history buffer is much harder.

Where the difference really matters is when the error is in previously defined 
objects.

>>> def f():
...   return a

>>> f()
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 2, in f
NameError: name 'a' is not defined

versus (Shell)

>>> def f():
return a

>>> f()
Traceback (most recent call last):
  File "", line 1, in 
f()
  File "", line 2, in f
return a
NameError: name 'a' is not defined

--
nosy: +terry.reedy

___
Python tracker 

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



[issue23035] python -c: Line causing exception not shown for exceptions other than SyntaxErrors

2014-12-12 Thread Arfrever Frehtes Taifersar Arahesis

Arfrever Frehtes Taifersar Arahesis added the comment:

It should not be more complex to read a line from a command line argument than 
to read a line from a regular file.

--

___
Python tracker 

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



[issue23035] python -c: Line causing exception not shown for exceptions other than SyntaxErrors

2014-12-12 Thread STINNER Victor

STINNER Victor added the comment:

SyntaxError exceptions have a text attribute which contains the line where the 
error occurred. It's really a special case. For other exceptions, Python only 
knows that the error occurred in the file called "".

Being able to display the line for any exception requires a complex 
development. I'm not interested to implement it, I don't think that it's very 
useful (compared to the time needed to develop it).

--
nosy: +haypo

___
Python tracker 

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



[issue23035] python -c: Line causing exception not shown for exceptions other than SyntaxErrors

2014-12-12 Thread STINNER Victor

Changes by STINNER Victor :


--
title: -c: Line causing exception not shown for exceptions other than 
SyntaxErrors -> python -c: Line causing exception not shown for exceptions 
other than SyntaxErrors

___
Python tracker 

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