I am trying to connect via telnet to a laboratory instrument. I'd like to extend the Telnet
class from the telnetlib
module in the standard library, to include functions specific to our instrument:
import telnetlib
class Instrument(telnetlib.Telnet):
def __init__(self, host=None, port=0, timeout=5):
super(Instrument,self).__init__(host, port, timeout)
All I am trying to do in this code is inherit the __init__
method from the parent class (telnetlib.Telnet
) and pass on the standard arguments, so I can add things to __init__
later. This formula has worked for me on other occasions; this time it gives me an error at the super()
statement when I try to instantiate:
TypeError: must be type, not classobj
I looked at the source code for telnetlib, and Telnet appears to be an old-style class (it doesn't inherit from object
) - I'm wondering if this could be the source of my problem? If so, how can it be overcome? I've seen some code examples where the derived class inherits both from the superclass and object
, though I'm not entirely sure if this is a response to the same problem as me.
Full disclosure: I have also tried using telnetlib.Telnet
in place of super()
, and from telnetlib import Telnet
with Telnet
in place of super()
. The problem persists in these cases.
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…