5

我不断得到我正在寻找的答案 plus 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()
4

1 回答 1

7

您在问题中的代码应该可以工作。您实际运行的代码必须是

print sabines.returnUpcomingTimes

而不是

print sabines.returnUpcomingTimes()
于 2012-11-28T12:55:03.317 回答