-1

I need to open an excel file with os. I know it's pretty easy as;

import os
os.system("start EXCEL.EXE file.xlsx") 

However, name of my file varies depending on my py file.

I defined a variable called "fileopenerfullname" and it is the name of the file i want to open.

But how can i insert "fileopenerfullname" variable in os.SYSTEM("start EXCEL ......")?

I tried very much including

os.system("start EXCEL.EXE fileopenerfullname")

Does not work.

I will be glad if anyone can help.

Charlie Clark
  • 18,477
  • 4
  • 49
  • 55

1 Answers1

1

Use formatted strings:

os.system(f"start EXCEL.EXE {fileopenerfullname}")

but don't forget your fileopenerfullname should include the extension .xlsx at the end.

Bemwa Malak
  • 1,182
  • 1
  • 5
  • 18