为什么Python在返回结果时显示“bound method….”以及如何停止它?

2024-06-20 15:10:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我不断地得到我想要的答案。

我将时间信息作为一个长时间字符串接收,将其设置为变量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()

Tags: to字符串fromimportselftimedef时间