我正在使用python和simplekml creator创建kml文件。 由于某些原因,它创建了两个kml文件,而不会创建第三个。数据对我来说很好。代码如下:
times=open("E:\\Python\Copyofresttable.csv","r")
import time
import csv
import simplekml
from time import strftime, localtime
dayoftheweekvariable = strftime("%A", localtime())
print dayoftheweekvariable
kml = simplekml.Kml()
if dayoftheweekvariable == "Monday":
for line in times:
a = line.split(',')
if a[2] == "Monday":
print a[5]
if dayoftheweekvariable == "Tuesday":
for line in times:
a = line.split(',')
if a[2] == "Tuesday":
print a[5]
if dayoftheweekvariable == "Wednesday":
for line in times:
a = line.split(',')
if a[1]== "Iron Hill" and a[2] =="Wednesday":
kml.newpoint(name="Iron Hill", coords=[(-75.605507,39.960504)], description=a[5])
kml.save("pythonmap.kml")
print "Creating KML"
if a[1]== "Side Bar and Resturant" and a[2] =="Wednesday":
kml.newpoint(name="Side Bar and Resturant", coords=[(-75.604805,39.960591)], description=a[5])
kml.save("pythonmap.kml")
print "Creating KML"
if a[1]== "Barnaby's" and a[2] =="Wednesday":
kml.newpoint(name="Barnaby's", coords=[(-75.604049,39.959488)], description=a[5])
kml.save("pythonmap.kml")
print "Creating KML"
很明显,在周三晚上测试这一点……至于最后三个if语句,不管我把它们放在什么顺序,它都会为铁山和巴纳比创造一个kml,但不是边栏。这是它返回的结果:
^{pr2}$错误消息调用what ever if语句在最上面。我被难住了。希望我的问题有意义(为什么它给我这个错误消息,而且不管if语句的顺序是什么,都只创建两个kml)
改变
收件人:
^{pr2}$在第一行中添加
为了确保你有足够的台词。。。在
更新:
你的回溯(在评论中)显示你的(第一个?!)
dayoftheweek
似乎是星期三,所以你的前两个ifs被忽略了。那么您的列表a
似乎没有任何条目。在你可以用
print("# a: {0}".format(len(a)))
来检查这个假设因此,如果少于3个条目,
a[2]==
必须失败,因为list index out of range
;-)啊,一开始我没看懂你的问题。如果每一个第一个if语句都抛出一个异常。。。。在
更新2: {Btw>你应该减少循环次数:
更新3:
你可以“欺骗”一点,如果你要修改一些行,可以做一些类似的事情:
相关问题 更多 >
编程相关推荐