Python 如何将迭代列表作为函数的参数运行-googlemaps

Python 如何将迭代列表作为函数的参数运行-googlemaps,python,excel,google-maps,Python,Excel,Google Maps,我是编程和python新手,所以请不要讨厌。我正在尝试构建一个程序,该程序将excel工作表中的地址列表转换为列表,然后使用google maps api检索每个地址之间的距离和时间。到目前为止,我只能硬编码一个地址。到目前为止,我唯一的问题是遍历gmaps.directions参数。我希望能在如何做到这一点上得到任何帮助。 所以最后,我想要多次和距离来比较它们。谢谢 from googlemaps import GoogleMaps import xlrd gmaps = GoogleM

我是编程和python新手,所以请不要讨厌。我正在尝试构建一个程序,该程序将excel工作表中的地址列表转换为列表,然后使用google maps api检索每个地址之间的距离和时间。到目前为止,我只能硬编码一个地址。到目前为止,我唯一的问题是遍历gmaps.directions参数。我希望能在如何做到这一点上得到任何帮助。 所以最后,我想要多次和距离来比较它们。谢谢

from googlemaps import GoogleMaps
import xlrd



gmaps = GoogleMaps('gmaps api')

wb = xlrd.open_workbook('addressbook.xlsx')
ws1 = wb.sheet_by_name('Sheet1')
ws2 = wb.sheet_by_name('Sheet2')
col1 = ws1.col_values(1)
col2 = ws2.col_values(1)



dirs = gmaps.directions(col1[0] ,col2[0])
time = dirs['Directions']['Duration']['seconds']
dist = dirs['Directions']['Distance']['meters']



print time 
print dist

尝试尽可能接近你已经拥有的东西:

from googlemaps import GoogleMaps
import xlrd



gmaps = GoogleMaps('gmaps api')

wb = xlrd.open_workbook('addressbook.xlsx')
ws1 = wb.sheet_by_name('Sheet1')
ws2 = wb.sheet_by_name('Sheet2')
col1 = ws1.col_values(1)
col2 = ws2.col_values(1)


for c1 in col1:
    for c2 in col2:
        dirs = gmaps.directions(c1 , c2)
        time = dirs['Directions']['Duration']['seconds']
        dist = dirs['Directions']['Distance']['meters']

        print time 
        print dist

我不知道你对编程一般来说有多陌生,但不管怎样,看起来应该有一个教程

是的,我正试图把学习python作为一种爱好。谢谢你的帮助,我嫉妒你的知识。如果我使用zip,那么我的两张excel表格必须有相同数量的地址。还有其他内置函数可以使用所有地址排列吗?@luketoboot更简单。在上面编辑。有一个类似于zip itertools.product的函数,但double for循环可能更简单。