
当我尝试运行代码时收到属性错误。
with ParamExample(URI) as pe:
with MotionCommander(pe, default_height=0.3)as mc:
这是发生错误的地方。
Traceback (most recent call last):
File "test44.py", line 156, in

0

2
评论 1
cc果冻儿

更多代码将不胜感激(特别是ParamExample实现),但我假设您缺少该类的__enter__(并且可能)方法。__exit__
当您在 python 中使用with块时,with 语句中的对象会__enter__调用它的方法,with运行内部的块,然后__exit__调用(如果引发了异常信息,则可选地带有异常信息)。因此,如果你的类没有__enter__定义,你会看到这个错误。
旁注:您需要缩进第二个with块,使其实际上在第一个块内,或者将这两行替换为
with ParamExample(URI) as pe, MotionCommander(pe, default_height=0.3) as mc:
这与嵌套这两个上下文管理器(with块使用的对象的名称)相同。
2022-02-07 14:55:49

0
- 没有更多了 -
Python互动课话题
0/300
请先 登录 后发表评论~