Python如何获取实例的基本实例?

mar*_*mnl 4 python python-2.6

在C#我会去:

myObj.base
Run Code Online (Sandbox Code Playgroud)

我有一个继承自date.datetime的Date类.Date类会覆盖__gt__(),__lt__()因此在使用<>运算符时会调用它们.我不想使用这些覆盖 - 我想在Date实例上使用date.datetime方法.

hoc*_*chl 6

使用super()以获得超对象.键入help(super)Python命令提示符.

从手册:

class super(object)
 |  super(type) -> unbound super object
 |  super(type, obj) -> bound super object; requires isinstance(obj, type)
 |  super(type, type2) -> bound super object; requires issubclass(type2, type)
 |  Typical use to call a cooperative superclass method:
 |  class C(B):
 |      def meth(self, arg):
 |          super(C, self).meth(arg)
Run Code Online (Sandbox Code Playgroud)