Pyserial 与 __init__ 错误
我正在尝试创建一个使用 python 初始化串行端口连接的模块:
import serial
class myserial:
def __init__(self, port, baudrate)
self = serial.Serial(port, baudrate)
当我在 Python 中运行此模块时,我收到一条 AttributeError 消息,指出 self 没有打开属性。有谁知道上面这段代码有什么问题吗?任何帮助将不胜感激。
谢谢
I'm trying to create a module that initializes a serial port connection using python:
import serial
class myserial:
def __init__(self, port, baudrate)
self = serial.Serial(port, baudrate)
When I run this in Python I get an AttributeError message stating that self does not have an attribute open. Does anyone have any idea what's wrong with this code above? Any help would be greatly appreciated.
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你想做什么,分配给
self
?请参阅 为什么 Python 对象中的 `self` 是不可变的? 以获得答案讨论这个。也许您想详细说明您实际上正在尝试做的事情。
What are you trying to do, assigning to
self
? See Why is `self` in Python objects immutable? for an answer that discusses this.Perhaps you want to elaborate more on what you are actually trying to do.
您应该将 Serial 对象设置为 self 的成员,而不是直接设置为 self
像这样:
HTH
You should be setting the Serial object to a member of self, rather than directly to self
Something like this:
HTH