1

I have seen this question: How can I read a file even when getting an "in use by another process" exception? Is there an equivalent way to do this using Python on Windows 7?

I need to modify a file but still let other processes read it while it's open in Python. The available modes, according to Python doc are "r","w","a",and "r+", which stand for read, write (overwrite), append, and read/write. I don't see a way to set "FileShare" modes.

Community
  • 1
  • 1
PhilMacKay
  • 865
  • 2
  • 10
  • 22
  • 1
    CPython use the C runtime to open files, which opens with read and write sharing, but not delete sharing. You shouldn't need to do anything extra to allow other processes to modify the file while you have it open in Python. They just can't delete or rename it. – Eryk Sun Mar 24 '17 at 21:45

1 Answers1

3

If you need fine control over the sharing mode, you can use win32file.CreateFile to open the file. ActiveState docs are here.

cco
  • 5,873
  • 1
  • 16
  • 21