(original) (raw)
On Tue, Feb 24, 2015 at 5:37 PM, Ethan Furman <ethan@stoneleaf.us> wrote:
On 02/24/2015 02:58 AM, Chris Angelico wrote:
\> On Tue, Feb 24, 2015 at 7:40 PM, M.-A. Lemburg <mal@egenix.com> wrote:
\>> I think the easiest way would be to tweak the error message
\>> output to indicate the real problem.
\>>
\>> At the moment, you get:
\>>
\>>>>> open('c:\\test.txt')
\>> Traceback (most recent call last):
\>> File "", line 1, in
\>> FileNotFoundError: \[Errno 2\] No such file or directory: 'c:\\test.txt'
\>>
\>> which isn't helpful.
\>
\> The problem isn't the cases where the file can't be found. Those can
\> be dealt with fairly easily, one way or another. The problem is much,
\> much earlier, when the student was using "c:\\sample.txt" and
\> everything was working fine. Then he changed the code over to use his
\> own file instead of the provided sample, and at the same time,
\> switched from using open() to using csv.reader(open()), and moved all
\> the code into a function, and fixed three other bugs, and now it isn't
\> working. And he can't figure out why.
\>
\> That's why I'd like "c:\\sample.txt" to raise a warning.
\>
\> Should I start writing up a PEP? Is that the way forward with this?
Go for it.
I think the solution will be two pieces:
\- deprecating unknown backslash-escapes, with the goal of eventually being a SyntaxError
(this removes a wart from the language, as well as allowing a warning backport to 2.7)
\- M.A.Lemburg's idea of changing the exception message in key places to make a successful
backslash replace obvious
(FileNotFoundError: \[Errno 2\] No such file or directory: 'c:\[\\t\]est.txt' - warning: embedded escapes)
Any ideas on how this check could be implemented? How would it distinguish \\t from an actual tab in the string literal, or "C:\\x64-python" from "C:\\d-python"...?
\--
\~Ethan\~
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/thomas%40python.org
Thomas Wouters <thomas@python.org>
Hi! I'm an email virus! Think twice before sending your email to help me spread!
Hi! I'm an email virus! Think twice before sending your email to help me spread!