csv - error of opening a file located in a remote server from python -
I need to read a CSV file located on server in Python 3.2 on Win7.
The file name is
csv_file = file_loc = '\\ serverName.myCompanyName.com \\ mypath \\ files \\ myfile.csv' open (file_loc, ' R ') # with error as csv_file !!! Csv_reader = csv.freader (csv_file, delimiter = ',')
Error:
IOError: [errno 2] Such a file or directory : '\\ serverName.myCompanyName.com \\ mypath \\ files \\ myfile.csv'
But, I can access the folder and can open the file from win 7.
Thanks
to launch UNC path Two backslashes are required for, and To avoid this, you are only one of the above codes
Try this:
file_loc = '\\\\ serverName.myCompanyName.com \\ mypath \\ Files \ \ Myfile.csv '
or this:
file_loc = r' \\ serverName.myCompanyName.com \ mypath \ Files \ myfile.csv '
The latter is an raw string in which there is no need to avoid backslash (among the others).
The path you can successfully access the file by using explorer or similar, it is the same path that should be present in your code after avoiding. (That is what you get when you get the print
value).
Comments
Post a Comment