In jython, I have a class of objects defined like this:
class Item:
def __init__(self, pid, aisle, bay, hits, qtyPerOrder):
self.pid = pid
self.aisle = int(aisle)
self.bay = bay
self.hits = int(hits)
self.qtyPerOrder = int(qtyPerOrder)
I have created a class list called "list" of the items in the class with 4000~ lines that look like this:
'PO78141', 13, ' B ', 40
I'm trying to randomly select a number within the range of 3 and 20 called x. Then, the code will select x number of lines in the list.
For example: if x = 5 I want it to return:
'PO78141', 13, ' B ', 40
'MA14338', 13, ' B ', 40
'GO05143', 13, ' C ', 40
'SE162004', 13, ' F ', 40
'WA15001', 13, ' F ', 40
EDIT Ok, that seems to work. However, it is returning this <main.Item object at 0x029990D0>. how do i get it to return it in the format above?
Remark - I renamed the list to
lst
. Assuming that you have a list of objects, try the following:You can use the
random
module to both pick a number between 3 and 20, and to take a sample of lines: