l******9 发帖数: 579 | 1 【 以下文字转载自 JobHunting 讨论区 】
发信人: light009 (light009), 信区: JobHunting
标 题: error of opening a file located in a remote server from pyton
发信站: BBS 未名空间站 (Sun Jul 27 19:03:52 2014, 美东)
I need to access read a csv file located in a server from python 3.2 on win7.
The file name is
csv_file =
file_loc = '\serverName.myCompanyName.com\mypath\Files\myfile.csv'
with open(file_loc , 'r') as csv_file # error !!!
csv_reader = csv.reader(csv_file, delimiter=',')
error:
IOError: [Errno 2] No such file or directory: '\serverName.myCompanyName
.com\mypath\Files\myfile.csv'
But, I can access the folder and open the file from win 7 .
Thanks | n*****t 发帖数: 22014 | 2 两个斜杠?不懂 python,不过看着你这个打开方式没说明协议啊
win7.
【在 l******9 的大作中提到】 : 【 以下文字转载自 JobHunting 讨论区 】 : 发信人: light009 (light009), 信区: JobHunting : 标 题: error of opening a file located in a remote server from pyton : 发信站: BBS 未名空间站 (Sun Jul 27 19:03:52 2014, 美东) : I need to access read a csv file located in a server from python 3.2 on win7. : The file name is : csv_file = : file_loc = '\serverName.myCompanyName.com\mypath\Files\myfile.csv' : with open(file_loc , 'r') as csv_file # error !!! : csv_reader = csv.reader(csv_file, delimiter=',')
| l**********n 发帖数: 8443 | 3 Remember that backslash is an "escape" character so
you must us r"" or double the number of backslashes
without the "r":
path="\servername\share\folder\file.ext"
OR Use forward slashes to specify the UNC Path:
open('//HOST/share/path/to/file') |
|