使用python从Fileshare-system打开文件

时间:2016-09-08 09:05:11

标签: python pandas

我试图从我们公司的Filesharing-System打开一个文件。这是脚本代码:

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('\\Q4DEE1SYVFS.ffm.t-systems.com\pasm$\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是:\ Q4DEE1SYVFS.ffm.t-systems.com \ pasm $ \ Berichte_SQL \ HVL.csv

当我启动脚本时,我收到以下错误:

Traceback (most recent call last):
  File "C:/Users/A52113242/Desktop/PROJEKTE/[INPROGRESS] AUSWERTUNG COIN + HVL/hvl_convert.py", line 13, in <module>
    hvl = pd.read_csv('Q4DEE1SYVFS.ffm.t-systems.com\pasm$\Berichte_SQL\HVL.csv', sep='|', encoding='latin1', low_memory=False)
  File "C:\Users\A52113242\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\A52113242\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\A52113242\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\A52113242\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\A52113242\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'Q4DEE1SYVFS.ffm.t-systems.com\\pasm$\\Berichte_SQL\\HVL.csv' does not exist

所以我的问题是路径是否存在问题或者是否缺少权限。你有什么想法吗?

谢谢!

编辑:

现在我试图打开文件:

f = open('\\Q4DEE1SYVFS.ffm.t-systems.com\pasm$\RFM\Berichte_SQL\HVL.csv','w')

尝试打开文件后,我收到此错误:

Traceback (most recent call last):
  File "C:/Users/A52113242/Desktop/PROJEKTE/[INPROGRESS] AUSWERTUNG COIN + HVL/hvl_convert.py", line 13, in <module>
    f = open('\\Q4DEE1SYVFS.ffm.t-systems.com\pasm$\Berichte_SQL\HVL.csv','w')
TypeError: an integer is required (got type str)

1 个答案:

答案 0 :(得分:1)

在处理UNC字符串或Windows字符串时,最好使用 $records = stripslashes($_POST['records']); $data = json_decode($records, true); //var_dump($_POST); // echo 'console.log("PHP: '.$data.'")', exit; foreach($data as $row) { $item[] = $row['item']; } for($i=0; $i<count($data);$i++){ $sqlQuery = "INSERT INTO tab_list (item) VALUES (?)"; //within for if($statement = $conexao->prepare($sqlQuery)){ $statement->bind_param("s", $item[$i]); $statement->execute(); $success= true; }else{ $erro = $conexao->error; $success = false; } } $sucess = array("success" => mysqli_errno($conexao) == 0); echo json_encode(array( "success" => $sucess )); $statement->close(); $conexao->close(); (原始)前缀声明常量字符串:

r

没有这样做导致一些字符被解释:

pd.read_csv(r'\\Q4DEE1SYVFS.ffm ...')

的产率:

print("foo\test")

同样适用于许多小写字符(`\ t,\ n,\ v,\ b,\ x ...)。

双反斜杠意味着“逃避反斜杠”并转换为单反斜杠。

foo est   (tabulation has been inserted)

的产率:

print('\\ddd')

因此你的路径不正确。

但这里还有更多。您不应该出现\ddd 错误。所以我在你的一条评论中发现了这个问题:有一些看不见的字符会造成麻烦。我在pyscripter中粘贴你的评论路径,并将其分配给一个变量,然后执行此操作:

expected int found str

只需重写字符串的最后一部分即可。

PS:记事本++无法看到奇怪的字符。我听说SciTe倾向于让那些人过去。 Pyscripter看到了他们。