5

I keep getting the answer I am looking for plus bound method tramStop.returnUpcomingTimes of <__main__.tramStop instance at 0x141d030>.

I receive my time information as a long string of times, I set that = to a variable SabinesTimes, and then convert it from a string to a list (in order to be able to iterate through the times rather than characters).

Here is my code:

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()
wisnewski.robert
  • 85
  • 1
  • 3
  • 7
  • @delnan.. I assume an instance of `ligne` class. – Rohit Jain Nov 28 '12 at 12:46
  • 1
    @RohitJain What makes you assume that? The use in `returnUpcomingTimes` indicates it's iterable, but `ligne` objects are not iterable. –  Nov 28 '12 at 12:58
  • SabinesTimes is a list of times which is what returnUpcomingTimes is iterating through. tramStop class is inheriting from Ligne class. EDIT. SabinesTimes = 04:55 05:05 05:10 05:20 05:35 05:45 05:58 06:08 06:14 06:20" SabinesTimes = ','.join(shlex.split(SabinesTimes)) SabinesTimes = SabinesTimes.split(",") – wisnewski.robert Nov 28 '12 at 13:24
  • 2
    @user1859844, unfortunately the code you just put in the comment doesn't help much. It's missing a quote mark and `shlex` isn't defined. Can you edit the original question so that the code sample is self-contained, runnable, and demonstrates your problem? Ideally I would be able to copy-paste it into my Python interpreter and it would show me exactly the problem you're having. – Kevin Nov 28 '12 at 13:47
  • @Kevin Agreed, though `shlex` is a standard library module. –  Nov 28 '12 at 14:37
  • Excellent, the code sample is now runnable! :-) But it seems to be working perfectly! Are you still seeing the `bound method` message? – Kevin Nov 28 '12 at 15:08
  • Voting to close, as the code clearly does not have the problem complained of. – Marcin Nov 28 '12 at 15:21
  • Here it is, working: http://ideone.com/fDhNv6 – Marcin Nov 28 '12 at 15:23

1 Answers1

7

Your code as in the question should work. The code you are actually running must be

print sabines.returnUpcomingTimes

rather than

print sabines.returnUpcomingTimes()
YXD
  • 31,741
  • 15
  • 75
  • 115
  • 2
    I would agree (and it's possible), but `I keep getting the answer I am looking for plus [...]` implies that's possibly not the case. Hence, this is either correct, or something very similar is occurring in whatever `SabinesTimes` is... and @delnan beat me to asking what that was :) – Jon Clements Nov 28 '12 at 12:57
  • Ah, thanks I didn't spot that. Let's wait and see... – YXD Nov 28 '12 at 13:04