Is there a simple way to wrap a built-in function for the whole package?
I get a package from Pypi. The package has many modules using built-in open() function. I like to redefine all the open() there with the default encoding 'utf-8', but not for code outside the package. Maybe I can put my def statement at the beginning of every module of this package, but just wondering is there a simple way of doing it? Best Regards, Jach -- https://mail.python.org/mailman/listinfo/python-list
Why won't the run-time error reporter point to the error position with a caret like the syntax error reporter does? It knows exactly where the error is.
Honestly this is the only thing in over half a decade of daily python use which has disappointed me enough to want to ask the devs: >>> print(1/) File "", line 1 print(1/) ^ SyntaxError: invalid syntax >>> print(1/1, 1/0, 1/1) Traceback (most recent call last): File "", line 1, in ZeroDivisionError: division by zero >>> print( ... 1 ... / ... 1 ... , ... 1 ... / ... 0 # line 8 ... , ... 1 ... / ... 1 ... ) Traceback (most recent call last): File "", line 8, in ZeroDivisionError: division by zero Why not print the caret? -- https://mail.python.org/mailman/listinfo/python-list
Re: Why won't the run-time error reporter point to the error position with a caret like the syntax error reporter does? It knows exactly where the error is.
On 7/31/2019 11:19 PM, jsals...@gmail.com wrote: Honestly this is the only thing in over half a decade of daily python use which has disappointed me enough to want to ask the devs: print(1/) File "", line 1 print(1/) ^ SyntaxError: invalid syntax SyntaxErrors mostly come from the parser, occasionally from the compiler, both of which have access to line and column. print(1/1, 1/0, 1/1) Traceback (most recent call last): File "", line 1, in ZeroDivisionError: division by zero This comes from the runtime engine, which only has access to line numbers, and even line numbers lie when a statement spans multiple lines. In CPython, the runtime engine is executing bytecodes, and bytecode do not correspond to column numbers. In something like "a + b / (2 * c + d//3)", if the denominator (which could be on multiple lines) is 0, where should a caret point? -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list