【发布时间】:2017-01-17 07:41:25
【问题描述】:
我准备了一个从 Excel 文件中读取的 Python 脚本:
import glob
import pandas as pd
import StringIO
import sys
import os
from xlrd import open_workbook
filelocation = str(sys.argv[0])
outputlocation = str(sys.argv[1])
FileExtension = str(sys.argv[2])
Separator = str(sys.argv[3])
#filelocation = 'C:\Desktop\MasterFile.xlsx'
#outputlocation = 'C:\Desktop\output'
wb = open_workbook(filelocation)
如果我通过 Jupyter Notebook 执行它,它会成功执行。
但是当我通过传递以下参数从命令行运行它时,它给了我一个错误
命令行:
python MergeFilesv1_2.py "C:\Desktop\MasterFile.xlsx" "C:\Desktop\output" ".csv" ","
错误信息:
Traceback (most recent call last):
File "MergeFilesv1_2.py",line 22, in <module>
wb = open_workbook(filelocation)
File "C:\Users\Sha\appData\Local\Enthought\Canopy\User\lib\site-packages\xlrd\_init__.py",line 441, in open_workbook
ragged_rows=ragged_rows,
File "C:\Users\Sha\appData\Local\Enthought\Canopy\User\lib\site-packages\xlrd\book.py",line 91, in open_workbook_xls
biff_version = bk.getbof(XL_WORKBOOK_GLOBALS)
File "C:\Users\Sha\appData\Local\Enthought\Canopy\User\lib\site-packages\xlrd\book.py",line 1230, in getbof
bof_error('Expected BOF record; found %r' %SELF.MEM[SAVPOS:SAVPOS + 8])
File "C:\Users\Sha\appData\Local\Enthought\Canopy\User\lib\site-packages\xlrd\book.py",line 1224, in bof_error
raise XLRDError('Unsupported format, or corrupt file:' + msg)
xlrd.biffh.XLRDError:Unsupported format, or corrupt file: Expected BOF record, found '\n# codin'
【问题讨论】:
标签: python python-2.7 enthought canopy