1

I have prepared a Python script which reads from Excel files:

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)

If I execute it through Jupyter Notebook, it executes successfully.

But when I run it from the command line by passing the below parameters it gives me an error

Command Line:

python MergeFilesv1_2.py "C:\Desktop\MasterFile.xlsx" "C:\Desktop\output" ".csv" ","

Error Message:

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'

1 Answer 1

2

Your file's name is also an argument.

Which means,
sys.argv[0] is assigned as MergeFilesv1_2.py,
sys.argv[1] is assigned as "C:\Desktop\MasterFile.xlsx" and so on.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks Lafexlos. Dont know how i miss that.
@SachinKamble To be a responsible member of the Stack Overflow community, please mark the answer given above as the correct answer and upvote it. For more explanation, please read the link given in the previous comment.
@JonathanMarch Actually my reputation is less then 15 hence i cannot do that
Just fixed that! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.