So, I have a relatively confusing setup for something I'm working on, explaining the following:
This is python. and a rougher plan, but it covers everything I need. Although the next function of the process is the same, so feel free to clean it if you want.
some_event_timer():
events.process_next()
class Event_queue:
def __init__(self):
self.events = []
def push(self, event, parameters):
self.events.insert(len(self.events), event, parameters)
def process_next(self):
event = self.pop(0)
event[0](event[1])
class Foo:
def __init__(self, start_value = 1):
self.value = start_value
def update_value(self, multiple):
self.value *= multiple
def return_bah(self)
return self.value + 3
class Bar:
def __init__(self, number1, number2):
self.init = number1
self.add = number2
def print_alt_value(self, in_value):
print in_value * (self.init + self.add)
These are the barebones of what I have, but this illustrates my problem: Running below
events2 = Event_queue2()
foo1 = Foo(4)
bar1 = Bar(4, 2)
events2.push(foo1.update_value,1.5)
events2.push(bar1.print_alt_value,foo1.value)
events2.push(bar.print_alt_value,foo1.return_bah())
events2.process_next()
events2.process_next()
events2.process_next()
It was originally expected that my conclusion would be 36 6 * (4 + 2)
I know why it is not there, foo1.value and foo1.return_bah () are passed as an evaluated parameter (correct term?). I really want to pass a reference to a variable or a reference to a method, and not evaluate it when I put it in the event queue.
Can anybody help me.
, , .
, , :
Python
Python
, .
, , , , foo1.return.bah process_next, , , , event_queue .
:
, , :
, , , .
, .
:
names = ["test1", "test2"]
for name in names:
names_objs[name] = Foo(4)
for name in names_list:
events2.push(lambda: names_objs[name].update_value(2))
. , name_objs [name], name , .
, :
name_obj_hold = name_objs[name]
. name_obj_hold, .
- funcs. , , .
, , - : names_objs [name].some_func (#something #)
, #something # ( , ), .