我一直在寻找我正在寻找的答案加上bound method tramStop.returnUpcomingTimes of <__main__.tramStop instance at 0x141d030>
。
我收到我的时间信息很长一段时间,我将=设置为变量SabinesTimes,然后将其从字符串转换为列表(以便能够遍历时间而不是字符)。
这是我的代码:
from datetime import datetime
from time import strftime
import shlex # <http://stackoverflow.com/questions/6868382/python-shlex-split-ignore-single-quotes>
import types
# SabinesTimes is given to me as one long string, I need to iterate through each time and compare to current time. So I convert it to a comma delineated list.
SabinesTimes = "04:55 05:55 06:10 07:20 08:35 09:45 10:58 11:00 12:00 13:00 14:00 15:00 16:00 17:00 18:00 19:00 20:00 21:00 22:00 23:59"
SabinesTimes = ','.join(shlex.split(SabinesTimes))
SabinesTimes = SabinesTimes.split(",")
class ligne():
def __init__ (self, stops):
self.stops = stops
def returnAllStopsOnLigne(self):
return stops
# inherits from Ligne
class tramStop(ligne):
def __init__ (self, times):
self.times = times
def returnUpcomingTimes(self):
now = strftime("%H:%M")
Departing_Trams = [i for i in self.times if i>= now]
return Departing_Trams
sabines = tramStop(SabinesTimes)
# the goal is to print all times greater than the current time at sabines.returnUpcomingTimes
print sabines.returnUpcomingTimes()
答案 0 :(得分:7)
问题中的代码应该有效。您实际运行的代码必须是
print sabines.returnUpcomingTimes
而不是
print sabines.returnUpcomingTimes()