0

I'm using openpyxl module in python to access a file in a path. But my file path looks like below and it is on network drive

"\\rsc.secad.com\hdrive\shared\test.xlsx"

To escape '\\' backslashes in above path I have added \ to it ,as shown in below code.

from openpyxl import load_workbook
fp = "\\\rsc.secad.com\\hdrive\\shared\\test.xlsx"
wb = load_workbook(fp)

And when I ran the program, I got following error.

OSError: [Errno 22] Invalid argument:"\\\rsc.secad.com\\hdrive\\shared\\test.xlsx"

Is there any way to access the path with double backslashes in it using openpyxl ?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Scarface
  • 359
  • 2
  • 13
  • have you tried using absolute paths? – 3NiGMa Oct 26 '19 at 03:02
  • @3NiGMa No, I didn't try it. I have no idea about it. can it be implemented along openpyxl ? – Scarface Oct 26 '19 at 03:05
  • can you move the python script into the same directory (folder) as the excel file, then change `fp` to `test.xlsx`? – 3NiGMa Oct 26 '19 at 03:10
  • @3NiGMa the given path is a network location/drive . Where as my python interpreter is on local drive. We are trying run it using command prompt – Scarface Oct 26 '19 at 03:21

1 Answers1

1

Well, you could simply use the forward slash instead like this

fp = "//rsc.secad.com/hdrive/shared/test.xlsx"
Shiv
  • 151
  • 6
  • was thinking this, although in what situation would forward slashes work and not double backslashes? – 3NiGMa Oct 26 '19 at 08:10
  • Answer is right here https://stackoverflow.com/questions/46805462/what-is-the-difference-between-using-and-in-specifying-folder-location-in-p – Shiv Oct 26 '19 at 14:37