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


Groups > comp.lang.python > #25153 > unrolled thread

Adding to a List and displaying quantity in the list

Started byShamefaced <manengstudent@gmail.com>
First post2012-07-10 12:15 -0700
Last post2012-07-10 13:51 -0700
Articles 3 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  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

#25153 — Adding to a List and displaying quantity in the list

FromShamefaced <manengstudent@gmail.com>
Date2012-07-10 12:15 -0700
SubjectAdding to a List and displaying quantity in the list
Message-ID<e16d39fa-161b-409e-9b6b-0238ee262bbd@googlegroups.com>
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.

[toc] | [next] | [standalone]


#25155

FromJohn Gordon <gordon@panix.com>
Date2012-07-10 20:30 +0000
Message-ID<jti3d7$q8e$1@reader1.panix.com>
In reply to#25153
In <e16d39fa-161b-409e-9b6b-0238ee262bbd@googlegroups.com> Shamefaced <manengstudent@gmail.com> writes:

>         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)

What is self.acquired?  Judging from earlier code it appears to be a
function, but here you're appending it to leavelist.  Did you really mean
to append a function object to leavelist?

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon@panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

[toc] | [prev] | [next] | [standalone]


#25156

FromShamefaced <manengstudent@gmail.com>
Date2012-07-10 13:51 -0700
Message-ID<348af93f-60b0-4947-b3e7-673fd8b100ac@googlegroups.com>
In reply to#25155
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) 

Yeah, I should have changed that back to :
leavelist.append(self.name) -- my thinking was that it would append the name of each item to the list.? 

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web