我试图从我们公司的文件共享系统中打开一个文件。以下是脚本的代码:
import sys
import xlrd
from tkinter import *
import pandas as pd
import time
from os import *
#hvl_file_path = filedialog.askopenfilename()
save_path = filedialog.asksaveasfilename(initialdir="C:/", defaultextension=".xlsx")
t1 = time.clock()
hvl = pd.read_csv('\\-----Berichte_SQL\HVL.csv', sep='|', encoding='latin1', low_memory=False)
hvl.to_excel(save_path, index=False)
t2 = time.clock()
t_ges = t2 - t1
print(t_ges)您可以看到file_path是:-Berichte_SQL\HVL.csv
启动脚本时,会得到以下错误:
Traceback (most recent call last):
File "C:/Users/-----/Desktop/PROJEKTE/[INPROGRESS] AUSWERTUNG COIN + HVL/hvl_convert.py", line 13, in <module>
hvl = pd.read_csv('------\Berichte_SQL\HVL.csv', sep='|', encoding='latin1', low_memory=False)
File "C:\Users\------\AppData\Local\Downloaded Apps\Winpython\python-3.4.3\lib\site-packages\pandas\io\parsers.py", line 474, in parser_f
return _read(filepath_or_buffer, kwds)
File "C:\Users\------\AppData\Local\Downloaded Apps\Winpython\python-3.4.3\lib\site-packages\pandas\io\parsers.py", line 250, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "C:\Users\------\AppData\Local\Downloaded Apps\Winpython\python-3.4.3\lib\site-packages\pandas\io\parsers.py", line 566, in __init__
self._make_engine(self.engine)
File "C:\Users\------------\AppData\Local\Downloaded Apps\Winpython\python-3.4.3\lib\site-packages\pandas\io\parsers.py", line 705, in _make_engine
self._engine = CParserWrapper(self.f, **self.options)
File "C:\Users\----------\AppData\Local\Downloaded Apps\Winpython\python-3.4.3\lib\site-packages\pandas\io\parsers.py", line 1072, in __init__
self._reader = _parser.TextReader(src, **kwds)
File "pandas\parser.pyx", line 350, in pandas.parser.TextReader.__cinit__ (pandas\parser.c:3187)
File "pandas\parser.pyx", line 594, in pandas.parser.TextReader._setup_parser_source (pandas\parser.c:5930)
OSError: File b'----------\\Berichte_SQL\\HVL.csv' does not exist因此,我的问题是,路径是否有问题,还是缺少权限的点。你有什么想法吗?
谢谢!
编辑:
现在我试着打开文件:
f = open('\\---------\Berichte_SQL\HVL.csv','w')尝试用open打开文件后,我得到以下错误:
Traceback (most recent call last):
File "C:/Users/--------ROJEKTE/[INPROGRESS] AUSWERTUNG COIN + HVL/hvl_convert.py", line 13, in <module>
f = open('\\---------------\Berichte_SQL\HVL.csv','w')
TypeError: an integer is required (got type str)发布于 2016-09-08 11:49:58
在处理UNC字符串或Windows字符串时,最好使用r (raw)前缀声明常量字符串:
pd.read_csv(r'\\Q4DEE1SYVFS.ffm ...')不这样做会导致一些字符被解释:
print("foo\test")产量:
foo est (tabulation has been inserted)许多小写字符(‘\t,\n,\v,\b,\x .)也是如此。
双反斜杠的意思是“逃避反斜杠”,并转换成一个反斜杠。
print('\\ddd')产量:
\ddd因此,您的路径是不正确的。
但这里还有更多。您不应该得到expected int found str错误。所以我在你的一个评论中发现了这个问题:有一些看不见的字符在制造麻烦。我将您的注释中的路径粘贴到拟写器中,并将其分配给一个变量,然后如下所示:
>>> z=r"\\Q4DEE1SYVFS.ffm.t-systems.com\pasm$\Berichte_SQL\HVL.csv"
>>> z
'\\\\Q4DEE1SYVFS.ffm.t-systems.com\\pasm$\\Berichte_SQL\\HVL\xe2\x80\x8c\xe2\x80\x8b.csv'只要重写字符串的最后一部分,它就能工作了。
PS: notepad++没有看到奇怪的字符。我听说SciTe也有一种让这些事情过去的倾向。派克普特看到他们了。
https://stackoverflow.com/questions/39386825
复制相似问题