Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么Python会显示";绑定方法……”;当返回结果时,如何使其停止?_Python_Methods - Fatal编程技术网

为什么Python会显示";绑定方法……”;当返回结果时,如何使其停止?

为什么Python会显示";绑定方法……”;当返回结果时,如何使其停止?,python,methods,Python,Methods,我不断得到我想要的答案,加上绑定方法tramStop.returnUpcomingTimes of 我以时间的长字符串形式接收时间信息,将其设置为变量SabinesTimes,然后将其从字符串转换为列表(以便能够遍历时间而不是字符) 这是我的代码: from datetime import datetime from time import strftime import shlex # <http://stackoverflow.com/questions/6868382/python-

我不断得到我想要的答案,加上
绑定方法tramStop.returnUpcomingTimes of

我以时间的长字符串形式接收时间信息,将其设置为变量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()
从日期时间导入日期时间
从时间导入strftime
导入shlex#
导入类型
#SabinesTimes作为一个长字符串提供给我,我需要迭代每次并与当前时间进行比较。所以我把它转换成一个逗号分隔的列表。
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(“,”)
类ligne():
定义初始化(自我,停止):
self.stops=停止
def RETURN ALLSTOPSONLIGNE(自):
回程站
#继承自Ligne
等级电车站(直线):
定义初始(自我,次数):
self.times=次
def返回时间(自身):
now=strftime(“%H:%M”)
出发电车=[我为我自己。如果我>=现在,时间为我自己]
返回出发的有轨电车
sabines=电车站(SabinesTimes)
#目标是在sabines.returnUpcomingTimes打印大于当前时间的所有时间
打印sabines.returnUpcomingTimes()

问题中的代码应该有效。您实际运行的代码必须是

print sabines.returnUpcomingTimes
而不是

print sabines.returnUpcomingTimes()

@德尔南。。我假设一个
ligne
类的实例。@RohitJain是什么让你这么认为的?在
returnUpcomingTimes
中使用表示它是可iterate的,但是
ligne
对象是不可iterate的。SabinesTimes是returnUpcomingTimes迭代的时间列表。tramStop类是从Ligne类继承的。编辑SabinesTimes=04:55 05:05:05:10 05:20 05:35 05:45 05:58 06:08 06:14 06:20“SabinesTimes=','。连接(shlex.split(SabinesTimes))SabinesTimes=SabinesTimes.split(“,”)@用户1859844,不幸的是,您刚才在注释中输入的代码没有多大帮助。它缺少引号,并且未定义
shlex
。您能否编辑原始问题,以便代码示例是自包含的、可运行的,并演示您的问题?理想情况下,我可以将其复制粘贴到Python解释器中,并且不会出现问题“你到底有什么问题?”凯文同意了,尽管
shlex
是一个标准的库模块。我同意(这是可能的),但
我一直得到我想要的答案加上[…]
意味着可能不是这样。因此,这要么是正确的,要么在任何
SabinesTimes
中都发生了类似的事情……而且@delnan击败我问那是什么:)啊,谢谢,我没有发现。让我们拭目以待。。。