Why exception from os.path.exists()?
Gregory Ewing
greg.ewing at canterbury.ac.nz
Mon Jun 11 02:28:02 EDT 2018
Chris Angelico wrote:
> I'd like to find out about that. If it doesn't work, it'll be easily
> provable that it can't be done.
Using the shell:
% touch colonic:name
% ls
colonic:name
% touch slashy/name
touch: slashy/name: No such file or directory
(It's trying to create a file in a directory called "slashy",
which doesn't exist.)
Using Python:
>>> open("colonic:name", "w").close()
>>> os.listdir(".")
['colonic:name']
>>> open("slashy/name", "w").close()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'slashy/name'
(Same reason as before.)
Using the GUI: I tried to use TextEdit to save a file with
a colon in the name. When I typed ":" into the filename box,
it substituted "-".
I was able to type "slashy/textfile" into the filename box
and save. In the shell it shows as:
% ls
slashy:textfile.rtf
Is that proof enough for you?
--
Greg
More information about the Python-list
mailing list