Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #25153

Adding to a List and displaying quantity in the list

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-out.readnews.com!transit3.readnews.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
From Shamefaced <manengstudent@gmail.com>
Newsgroups comp.lang.python
Subject Adding to a List and displaying quantity in the list
Date Tue, 10 Jul 2012 12:15:55 -0700 (PDT)
Organization http://groups.google.com
Lines 42
Message-ID <e16d39fa-161b-409e-9b6b-0238ee262bbd@googlegroups.com> (permalink)
NNTP-Posting-Host 86.41.105.168
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
X-Trace posting.google.com 1341947756 9560 127.0.0.1 (10 Jul 2012 19:15:56 GMT)
X-Complaints-To groups-abuse@google.com
NNTP-Posting-Date Tue, 10 Jul 2012 19:15:56 +0000 (UTC)
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=86.41.105.168; posting-account=tOLyQwoAAADWd7MQxZJDdwQtHuDYhVwk
User-Agent G2/1.0
Xref csiph.com comp.lang.python:25153

Show key headers only | View raw


Hi
I have coded a program whihc outputs what I like, but I am trying to modify it to add specific result info to a list and then display the number of items in the list. This is easy for me with basic code, but seems difficult when trying to adapt my program.
My code and explanation is as follows:

class Source(Process):
    """ Source generates customers randomly """

    def generate(self, number, meanTBA, resource):
        for i in range(number):
            c = Customer(name="Customer%02d" % (i+1,))
            activate(c, c.visit(b=resource))            
            #t = expovariate(1.0 / meanTBA)
            t = 10.0
            yield hold, self, t

class Customer(Process):
    """ Customer arrives, is served and  leaves """

    def visit(self, b):
        leavelist = [] /* Name of List defined */
        arrive = now()                          
        #tib = expovariate(1.0 / timeInBank)    
        tib = timeInBank                         
/* Console Output results start here */        
        print("%8.3f %s: Here I am" % (now()/60, self.name))
        yield (request, self, b), (hold, self,maxWaitTime)                      
        wait = now() - arrive                  
        if self.acquired(b): 
            print("%8.3f %s: Waited %6.3f" % (now()/60, self.name, wait))
            yield hold, self, tib
            yield release, self, b
            print("%8.3f %s: Finished" % (now()/60, self.name))
        else:
            print("%8.3f %s: Waited too long %6.3f" % (now()/60, self.name, wait) + " time units have passed - Customer has left")
            leavelist.append(self.acquired)
        print len(leavelist)

What I am looking to do is the "customers" who have "Waited too long" get added to my leavelist() as they occur.

Does this make sense?

Thank you.

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Adding to a List and displaying quantity in the list Shamefaced <manengstudent@gmail.com> - 2012-07-10 12:15 -0700
  Re: Adding to a List and displaying quantity in the list John Gordon <gordon@panix.com> - 2012-07-10 20:30 +0000
    Re: Adding to a List and displaying quantity in the list Shamefaced <manengstudent@gmail.com> - 2012-07-10 13:51 -0700

csiph-web