Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Adding to a List and displaying quantity in the list

Reply
Thread Tools

Adding to a List and displaying quantity in the list

 
 
Shamefaced
Guest
Posts: n/a
 
      07-10-2012
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.
 
Reply With Quote
 
 
 
 
John Gordon
Guest
Posts: n/a
 
      07-10-2012
In <(E-Mail Removed)> Shamefaced <(E-Mail Removed)> 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
http://www.velocityreviews.com/forums/(E-Mail Removed) B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

 
Reply With Quote
 
 
 
 
Shamefaced
Guest
Posts: n/a
 
      07-10-2012
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.?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Join Date: May 2006, Posts: 10 Reputation: HAOBBOY is an unknown quantity at this point (<10) Stopping Sorting Feature of Maps HAOBBoy@gmail.com C++ 3 05-17-2006 09:02 AM
quantity of JPS's/Servlets vs. resource consuming Przemek Klein Java 0 10-06-2005 12:20 PM
Saving The quantity of a textbox control between postbacks Gary Vidal ASP .Net 2 02-12-2004 01:04 AM
FS: Lucent ClearTrac V352, SDM-9350 Routers, $100 each, quantity of 20 available, must get these cleared out of our bank inventory Pudda Work VOIP 0 12-24-2003 07:32 PM
time quantity in vhdl Nav VHDL 3 10-02-2003 02:41 PM



Advertisments