On 2/24/2015 1:14 PM, Guido van Rossum wrote: > And I'd weigh the needs of users who know what they are doing somewhat > higher than educating newbies through error messages. While newbies are > most likely to try out open() with a string literal, in "real" programs > that is rare, and filenames are typically taken from the command line or > from some other source where the peculiarities of Python string literals > are irrelevant. I have been thinking about proposing a new how-to: Understanding Error Messages, with a section on tracebacks followed by an alphabetical listing of Exceptions that gives people problems, with possible solutions for each. The following begins my first draft. FileNotFoundError: Possible cause [Windows]: You used a normal string literal to create a filename, you used '\' as the path separator, and you forgot that Python (like most languages) treats '\' as a case-sensitive escape character. For example: "C:\Test" is 7 chars and works as a file name, while 'C:\test' is 6 chars, one a literal tab character. The latter does not work as a file name and will raise FileNotFoundError. Possible solutions: 1. Use raw string literals for Windows path names (r'C:\test'). 2 (recommended). Use '/' as the path separator ('C:/test'), just as one does on other systems. This always works when passing file names from Python to Windows, even though it sometimes does not work in Windows Command Prompt console. -- Terry Jan Reedy
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4