Python processes files with uppercase and lowercase names the same

I just found out about it today:
If I have an existing file named a111 and I want to create a new file named A111 in the same directory with Python:

f = file('A111', 'w') f.write('test') f.close() 

It will overwrite my a111 file and there is no A111 !!
How can I prevent this?

+4
source share
3 answers

This is not because of python. This is due to the case insensitivity of your base file system (I assume that HFS + in your case?). From wikipedia :

Not all file systems on Unix-like systems are case sensitive; Mac OS X defaults to case insensitive HFS +

The solution is to use a case-sensitive file system if you want to use it, or to use a different file name!

+8
source

It really reproduces for me.

 nixon:~ matt$ touch a111 nixon:~ matt$ python Python 2.7.2 (default, Nov 14 2011, 19:37:59) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> f = file('A111', 'w') >>> f.write('test') >>> f.close() >>> nixon:~ matt$ cat a111 test 

Also on mac.

 nixon:~ matt$ uname -a Darwin nixon.local 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386 i386 nixon:~ matt$ python --version Python 2.7.2 

I suspect you will find that what is happening is that we both use HFS, which is a case-insensitive file system.

+2
source

The Mac HFS + file system is not case sensitive by default, unless you perform the installation from scratch - one of the installation options includes case sensitivity.

+1
source

Source: https://habr.com/ru/post/1395526/


All Articles