Python 什么是;“自我行动”;什么意思?
这是什么意思Python 什么是;“自我行动”;什么意思?,python,Python,这是什么意思 self.action=env.process(self.run()) .action是默认方法吗 我不明白为什么这会自动启动运行过程 class Car(object): def __init__(self, env): self.env = env # Start the run process everytime an instance is created. self.action = env.process(self
self.action=env.process(self.run())
.action
是默认方法吗
我不明白为什么这会自动启动运行过程
class Car(object):
def __init__(self, env):
self.env = env
# Start the run process everytime an instance is created.
self.action = env.process(self.run())
def run(self):
while True:
print('Start parking and charging at %d' % self.env.now)
charge_duration = 5
# We yield the process that process() returns
# to wait for it to finish
yield self.env.process(self.charge(charge_duration))
这是什么意思
self.action=env.process(self.run())
它将调用方法env.process
的返回值与调用方法self.run
的返回值(不带参数)作为参数分配给属性self.action
由于这是\uuuu init\uuuu
序列化程序,因此它也会创建属性作为副作用
.action
是默认方法吗
不,这不是默认方法。事实上,它既不是一个方法(它是一个属性),也不是默认值(您正在创建它)。它是在该行中创建和初始化的self
属性
我不明白为什么这会自动启动运行过程
class Car(object):
def __init__(self, env):
self.env = env
# Start the run process everytime an instance is created.
self.action = env.process(self.run())
def run(self):
while True:
print('Start parking and charging at %d' % self.env.now)
charge_duration = 5
# We yield the process that process() returns
# to wait for it to finish
yield self.env.process(self.charge(charge_duration))
我不知道什么是“运行过程”
它将要做的是调用
self.run
方法,因为该方法被用作env.process
方法的参数,该方法反过来用于初始化self.action
属性。由于此代码位于初始值设定项中,因此每次实例化对象时都会调用它。您的代码中可能还有其他东西在使用action
属性;它本身没有任何特殊意义。你定义了一个叫做动作的属性,不确定问题是什么env
和action
是类实例的属性。完整代码在这里:真的不知道self.action为什么可以启动运行进程>启动运行进程的可能是调用self.run()
我想我现在明白了。非常感谢!!!:)