0

Hey guys,

Just as the title says, I want to implement using an excel spreadsheet as an argument for a python script. I already have the layout of the spreadsheet, but I want to be able to assign the variables in my python script from specific cells of the spreadsheet.

So, ideally I want to be able to type something like "script.py spreadsheet" in my cygwin command prompt.

Thanks,

kayoh

2
Contributors
3
Replies
7
Views
5 Years
Discussion Span
Last Post by Gribouillis
0

You only need to read the spreadsheet file in sys.argv and use the module xlrd

#!/usr/bin/env python
import sys
import xlrd

if __name__ == "__main__":
    assert len(sys.argv) == 2
    spreadsheet = sys.argv[-1]
    wb = xlrd.open_workbook(spreadsheet)
    sh = wb.sheet_by_index(0)
    my_variable = sh.cell_value(0,0) # access a cell

Get xlrd from pypi with the easy_install command.

Edited by Gribouillis: n/a

0

Thanks for the prompt response, however I'm having problems installing the xlrd module, could provide more details regarding the "easy_install" command?

I went here: http://pypi.python.org/pypi/xlrd and downloaded the MS Windows Installer, when I ran it it found where my python was installed but when I tried to import it into my script the module wasn't found.

Edited by kayoh: n/a

0

Thanks for the prompt response, however I'm having problems installing the xlrd module, could provide more details regarding the "easy_install" command?

I went here: http://pypi.python.org/pypi/xlrd and downloaded the MS Windows Installer, when I ran it it found where my python was installed but when I tried to import it into my script the module wasn't found.

You are probably using the cygwin version of python. To have easy_install, download setuptools as described here
http://pypi.python.org/pypi/setuptools#cygwin-mac-os-x-linux-other (the file to download is near the end of the web page). Once setuptools is installed, you can install xlrd (as well as 15000 other modules in pypi) by running easy_install xlrd on the cygwin command line (when a working internet connection is available).

Edited by Gribouillis: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.