1

我正在尝试在共享网络位置打开文件

open('\\int\GroupData\ITProSup\Operations Support\REMGROUP.txt','+r')

现在这变成了

nemonics>python main.py
eback (most recent call last):
le "main.py", line 41, in <module>
sys.exit(main())
le "main.py", line 36, in main
insert_file_into_db(con_S104838,open('\\int\GroupData\ITProSup\Operations Su
t\REMGROUP.txt','+r'))
NotFoundError: [Errno 2] No such file or directory: '\\int\\GroupData\\ITPro
\Operations Support\\REMGROUP.txt'

我已经尝试过这个线程使用 Python,如何访问 Windows 网络上的共享文件夹?但它确实注意到似乎对我有用。我正在运行 python 3.4.1 及其 windows 2012 服务器。

我也尝试过使用 os.path https://docs.python.org/3.4/library/os.path.html#os.path.normpath但运气不佳

C:\mnemonics>python main.py
Traceback (most recent call last):
  File "main.py", line 41, in <module>
    sys.exit(main())
  File "main.py", line 36, in main
    insert_file_into_db(con_S104838, open(os.path.normpath('\\int\GroupData\ITPr
oSup\Operations Support\REMGROUP.txt')))
FileNotFoundError: [Errno 2] No such file or directory: '\\int\\GroupData\\ITPro
Sup\\Operations Support\\REMGROUP.txt'

C:\mnemonics>python main.py
Traceback (most recent call last):
  File "main.py", line 42, in <module>
    sys.exit(main())
  File "main.py", line 37, in main
    open(os.path.normcase('\\int\GroupData\ITProSup\Operations Support\REMGROUP.
txt'),'+r'))
FileNotFoundError: [Errno 2] No such file or directory: '\\int\\groupdata\\itpro
sup\\operations support\\remgroup.txt'

任何帮助将不胜感激

4

1 回答 1

1

请注意,\应该转义到\\,所以\\应该是\\\\

请试试

'\\\\int\\GroupData\\ITProSup\\Operations Support\\REMGROUP.txt'

或者

'//int/GroupData/ITProSup/Operations Support/REMGROUP.txt'
于 2014-07-30T09:39:40.790 回答