python - python3 create/open file case sensitive Mac -


tried interneting , checking python3 documentation, can't seem fix following - i'm missing flag or something!

i want create , edit files in local directory . using python case-sensitive file names: have following behaviour:

~$ python3 python 3.5.2 (v3.5.2:4def2a2901a5, jun 26 2016, 10:47:25)  [gcc 4.2.1 (apple inc. build 5666) (dot 3)] on darwin type "help", "copyright", "credits" or "license" more information. >>> f = open("file.txt", "w") >>> f.write("hello\n") 6 >>> f.close() >>> del f >>> f = open("file.txt", "w") >>> f.write("bye\n") 4 >>> f.close() >>> del f >>> quit() ~$ ls applications    downloads       movies       public cloud           file.txt        music        intel desktop         jagex           documents    library documents       library         pictures ~$ cat file.txt  bye ~$ cat file.txt cat: file.txt: no such file or directory 

does know "file.txt" [with 'hello\n'] file has gone?

thanks!

edit1: i'm using osx sierra 10.12.1 precise.

that not (directly) related python os , filesystem. unix-like (linux , bsds example) have strict case sensitive file names: file.txt , file.txt 2 different files. on other hand on windows, if case insensitive version of same name exists, opened instead of creating new one. on windows, code have reopened (and erased because of w mode) same file. have no access mac, cannot whether same case.

but use python 3.5, can use x mode exclusive creation mode. in mode, if open call have opened existing file, error.

your code become:

~$ python3 python 3.5.2 (v3.5.2:4def2a2901a5, jun 26 2016, 10:47:25)  [gcc 4.2.1 (apple inc. build 5666) (dot 3)] on darwin type "help", "copyright", "credits" or "license" more information. >>> f = open("file.txt", "x") >>> f.write("hello\n") 6 >>> f.close() >>> del f >>> f = open("file.txt", "x") # raise ioerror... ... 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -