python - why I cannot import the class in SimPy -
learning simpy right now. using first example code, link https://simpy.readthedocs.org/en/latest/topical_guides/process_interaction.html
this part of code written in interactive mode. want put class ev individual python file named ev.py (shown below).
ev.py
class ev: def __init__(self, env): self.env = env self.drive_proc = env.process(self.drive(env)) self.bat_ctrl_proc = env.process(self.bat_ctrl(env)) self.bat_ctrl_reactivate = env.event() def drive(self, env): while true: # drive 20-40 min yield env.timeout(randint(20, 40)) # park 1–6 hours print('start parking at', env.now) self.bat_ctrl_reactivate.succeed() # "reactivate" self.bat_ctrl_reactivate = env.event() yield env.timeout(randint(60, 360)) print('stop parking at', env.now) def bat_ctrl(self, env): while true: print('bat. ctrl. passivating at', env.now) yield self.bat_ctrl_reactivate # "passivate" print('bat. ctrl. reactivated at', env.now) # intelligent charging behavior here … yield env.timeout(randint(30, 90))
then import file. run this:
from random import seed, randint seed(23) import simpy import ev env=simpy.environment() ev = ev.ev(env) env.run(until=150)
when comes step: ev=ev.ev(env), shows there error:
traceback (most recent call last):
file "stdin", line 1, in module
typeerror: constructor takes no arguments
Comments
Post a Comment