Python Twisted LineReceiver class variables? -
i'm using linereceiver class in python twisted library. see linereceiver source code mdethods setlinemode , setrawmode set class variable line_mode 1 or 0. there class variable called _buffer assume stores data sent on connection.
but why line_mode , _buffer class variables? doesn't mean if factory creates multiple instances of linereceiver (or protocols inherit linereceiver) if set line_mode=1 linereceiver protocol instances go line mode? , doesn't mean there 1 _buffer instances of linereceiver? don't understand. can please explain this?
ok figured out. yes linereceiver class indeed have class variables _buffer , line_mode. however, uses inside linereceiver methods instance variables same name. when python creates instance of class has class variables, creates instance variables of same name, , these instance variables have whatever value class variable had when instance created.
so example, instance can check self.line_mode value instance variable line_mode. if first time instance variable accessed, should have same value corresponding class variable. if change it, gets new value different of class variable. guess of hidden stuff goes on under hood in python.
you can still value of class variable line_mode accessing linereceiver.line_mode.
just thought i'd write in case else (like me) new python , twisted , got confused.
Comments
Post a Comment