I have this code:
import csv
tally=0
i=0
n=1
numb=2
count = sum(1 for row in csv.reader( open('cities.csv') ) )
cityname = csv.reader(open("cities.csv", "rb"))
citynames = []
citynames.extend(cityname)
for data in citynames:
citynames.append(data[0])
tally+=1
if tally>=count:
break
tally=0
cities_x = csv.reader(open("cities.csv", "rb"))
cities_list_x = []
cities_list_x.extend(cities_x)
names = []
for data in cities_list_x:
names.append(data[0])
timel=raw_input("When is your target landing time?<'0' to exit> ")
first_colonl=timel.find(":")
hoursl=timel[:first_colonl]
minutesl=timel[first_colonl+1:first_colonl+3]
secondsl=timel[first_colonl+4:first_colonl+6]
hours_secondsl=int(hoursl)*3600
minutes_secondsl=int(minutesl)*60
total_secondsl=hours_secondsl+minutes_secondsl+int(secondsl)
w = csv.writer(open('timer.csv','w'))
spamWriter = csv.writer(open('timer.csv', 'wb'), delimiter=' ',
quotechar=' ', quoting=csv.QUOTE_MINIMAL)
spamWriter.writerow(['city'] + [','] + ['travel time'] + [','] + ['send Time'] + [','+timel] )
while i in range(0,count):
time=raw_input("How long does it take to get to your target from "+str(names[i])+"?<'0' to exit> ")
first_colon=time.find(":")
hours=time[:first_colon]
minutes=time[first_colon+1:first_colon+3]
seconds=time[first_colon+4:first_colon+6]
hours_seconds=int(hours)*3600
minutes_seconds=int(minutes)*60
total_seconds=hours_seconds+minutes_seconds+int(seconds)
send_time=total_secondsl-total_seconds
send_hours=send_time/3600
send_minutes=(send_time-(send_hours*3600))/60
send_seconds=(send_time-((send_hours*3600)+(send_minutes*60)))
print "The send time is", send_hours,":", send_minutes,":",send_seconds
sendtime='=D1-'+chr(98)+str(numb)+'+48'
spamWriter.writerow([names[i]] + [','] + [sendtime] + [','] + [time])
i+=1
numb+=1
I need to format the variable 'sendtime' into hh:mm:ss so that it does not show up as a number with decimals in my spreadsheet. If anybody can provide me with code or explain the xlwt module better than their help manuals do that would be helpful.
Thanks,
Jaro