我已经能够让该列以独立列表的形式输出该列的值。但是,我需要保留这些值,并逐个使用它们来执行Amazon查找。亚马逊搜索并不是问题所在。让XLRD一次给出一个值一直是个问题。在Python中也有设置时间的有效方法吗?对于计时器问题,我找到的唯一答案是记录进程开始的时间,并从那里开始计数。我宁愿只有一个计时器。这个问题有两个部分,这里是我到目前为止所做的。
我使用xlrd加载电子表格,使用argv1将其复制到一个新的电子表格名称中,使用argv2;argv3我需要成为timer实体,但是目前还不是很远。
我试过了:
import sys
import datetime
import os
import xlrd
from xlrd.book import colname
from xlrd.book import row
import xlwt
import xlutils
import shutil
import bottlenose
AMAZON_ACCESS_KEY_ID = "######"
AMAZON_SECRET_KEY = "####"
print "Executing ISBN Amazon Lookup Script -- Please be sure to execute it python amazon.py input.xls output.xls 60(seconds between database queries)"
print "Copying original XLS spreadsheet to new spreadsheet file specified as the second arguement on the command line."
print "Loading Amazon Account information . . "
amazon = bottlenose.Amazon(AMAZON_ACCESS_KEY_ID, AMAZON_SECRET_KEY)
response = amazon.ItemLookup(ItemId="row", ResponseGroup="Offer Summaries", SearchIndex="Books", IdType="ISBN")
shutil.copy2(sys.argv[1], sys.argv[2])
print "Opening copied spreadsheet and beginning ISBN extraction. . ."
wb = xlrd.open_workbook(sys.argv[2])
print "Beginning Amazon lookup for the first ISBN number."
for row in colname(colx=2):
print amazon.ItemLookup(ItemId="row", ResponseGroup="Offer Summaries", SearchIndex="Books", IdType="ISBN")我知道这有点含糊。也许我应该尝试做一些像column = colname(colx=2)这样的事情,然后我可以做列中的行:任何帮助或方向都是非常感谢的。
发布于 2012-11-18 19:33:57
在您的代码中使用colname()只是返回列的名称(例如默认情况下是'C‘,除非你重写了它的名字)。此外,colname的使用不在工作簿内容的上下文范围内。我认为您可能想要使用正在加载的工作簿中的特定工作表,并且希望从该工作表中引用列的值(在您的示例中为2),这听起来是否正确?
wb = xlrd.open_workbook(sys.argv[2])
sheet = wb.sheet_by_index(0)
for row in sheet.col(2):
print amazon.ItemLookup(ItemId="row", ResponseGroup="Offer Summaries", SearchIndex="Books", IdType="ISBN")尽管我认为在查看对amazon.ItemLookup()的调用时,您可能希望引用row和,而不是到"row",因为后者只是一个字符串,而前者是for循环中名为row的变量的实际内容。
https://stackoverflow.com/questions/13439420
复制相似问题