Python : why a method from super class not seen?

霸气de小男生 提交于 2019-12-05 06:13:09
Brent Washburne

I dare say that the twisted/python/threadable.py code has a bug in it. __dict__ only returns the local attributes, not the inherited attributes. Other posts say to use dir() or inspect.getmembers() to get them.

The good news is that you are correct on your first idea that the write method is inherited. The bad news is that Twisted doesn't recognize inherited methods, so you have to write them yourself.

Saullo G. P. Castro

There is one workaround, just do:

NDailyLogFile.__dict__ = dict( NDailyLogFile.__dict__.items() + DailyLogFile.__dict__.items() )
threadable.synchronize(NDailyLogFile)

There is a problem here that you are using the class without having instantiated it. This workaround works because you are forcing to change the class attributes before the instantiation.

Another important comment ist that for a subclass of DailyLogFile the command super would not work, since DailyLogFile is a so called "old style class", or "classobj". The super works for the "new style" classes only. See this question for further information about this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!