why I cannot import the class in SimPy

137 views Asked by At

Learning SimPy right now. I am using the first example code, link https://simpy.readthedocs.org/en/latest/topical_guides/process_interaction.html

This part of code is written in interactive mode. I want to put the class EV into a individual python file which is named as 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 for 20-40 min    
            yield env.timeout(randint(20, 40))    
    
            # Park for 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 I import the file. I run it like this:

from random import seed, randint
seed(23)
import simpy
import Ev
env=simpy.Environment()
ev = Ev.EV(env)
env.run(until=150)

When it comes to step: ev=Ev.EV(env), It shows there is an error:

Traceback (most recent call last):

File "stdin", line 1, in module

TypeError: this constructor takes no arguments

0

There are 0 answers