On Fri, 01 Jun 2018 14:38:56 +0000, Grant Edwards wrote: > On 2018-06-01, Paul Moore <p.f.mo...@gmail.com> wrote: > >> Python allows strings with embedded \0 characters, so it's possible to >> express that question in Python - os.path.exists('a\0b'). What can be >> expressed in terms of the low-level (C-based) operating system API >> shouldn't be relevant. > > Python allows floating point numbers, so it is possible to express this > question in python: os.path.exists(3.14159). Is the fact that the > underlying OS/filesystem can't identify files via a floating point > number relevent? Should it return False or raise ValueError?
Certainly not a ValueError, that would be silly. The fact that it is an illegal value is subordinate to the fact that it is the wrong type. It should either return False, or raise TypeError. Of the two, since 3.14159 cannot represent a file on any known OS, TypeError would be more appropriate. But since "\0" is the correct type (a string), and the fact that it happens to be illegal on POSIX is a platform-dependent detail of no more importance than the fact that "?" is illegal on Windows, it should be treated as any other platform-dependent illegal file and return False. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson -- https://mail.python.org/mailman/listinfo/python-list