PermissionError: [Errno 13] Permission denied: 'Abc.xlsx'

Christian Gollwitzer auriocus at gmx.de
Thu Feb 10 15:39:05 EST 2022


Am 10.02.22 um 20:43 schrieb Chris Angelico:
> On Fri, 11 Feb 2022 at 06:41, Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
>>          While not tested with Excel, I /have/ encountered cases where an
>> application has locked the file for writing, but multiple readers are
>> permitted. Those would fail then if one attempts to write. {The other view
>> point is a library that does a complete open/read\write-all/close to memory
>> -- such an application might open/read/close, then Excel opens/locks, with
>> the application only learning of the change when it attempts the
>> open/write/close cycle}
>>
> 
> Yeah, I doubt Excel is that sophisticated. It's built on an assumption
> of single-user operation.
> 

It guards against multiple user opening the same file over network 
drives. All MS applications create lock files with weird names like 
~.original-name.xlsx etc. If you open a file on the network share, and a 
colleague tries to open it from a second machine, then he will get the 
message "File locked by user xy from machine z". See here for word: 
https://support.microsoft.com/en-us/topic/-the-document-is-locked-for-editing-by-another-user-error-message-when-you-try-to-open-a-document-in-word-10b92aeb-2e23-25e0-9110-370af6edb638

I believe (haven't tested) that this is cooperative locking only and it 
doesn't help if you alter the file from another program. On the same 
machine though, I think that Excel opens the file with a flag to lock it 
from other processes. At least that was my observation and also what the 
OP has described.

Hence it is impossible to concurrently write from Python into an open 
Excel file. One might ask what the real problem is the user is trying to 
solve. Is Excel a requirement, can it be swapped by a database engine?

Best regards,

	Christian


More information about the Python-list mailing list