0

I have multiple excel files in a folder and I want to open them using os library in python. I am using a command to open the excel file but it sometimes opens it in the read_only format. Command is:

os.startfile(path)

but it is open in the read_only mode and shows this message before opening it. enter image description here

I want to open it in edit mode, can somebody please help?

Vesper
  • 795
  • 1
  • 9
  • 21

2 Answers2

0

In order to open the file in edit mode, just specify it like this:

os.startfile(filename, 'edit')     # Can specify 'edit' as the operation
0

You should specify the operation that you want to do with startfile() method. For example, in this case you require 'edit', so: startfile(path, 'edit')

(https://docs.python.org/library/os.html#os.startfile)

David García Bodego
  • 1,058
  • 3
  • 13
  • 21
  • I did that but still it is saying that 'file in use' , read_only mode – Vesper Dec 09 '21 at 09:38
  • Side note: You can remove the Python version from the docs url and it will redirect to the latest version. E.g. https://docs.python.org/library/os.html#os.startfile will redirect to https://docs.python.org/3/library/os.html#os.startfile (notice the ``/3/`` in the second url) which will show the docs for 3.10.1 (which is the latest stable release currently). The 2.7 docs are somewhat outdated, unless the question is explicitely tagged as 2.7 – Mike Scotty Dec 09 '21 at 09:40