标签云

微信群

扫码加入我们

WeChat QR Code

This question already has an answer here:

I came upon this reading the python documentation on the super keyword:

If the second argument is omitted, the super object returned is unbound. If the second argument is an object, isinstance(obj, type) must be true. If the second argument is a type, issubclass(type2, type) must be true (this is useful for classmethods).

Can someone please give me an example of a distinction between passing a Type as a second argument versus passing an Object?

Is the documentation talking about an instance of an object?

Thank you.


This should give you some perspective: cafepy.com/article/python_types_and_objects/…

2018年08月22日18分23秒

karthikr Agreed, great article

2018年08月22日18分23秒

Or have a look at this question stackoverflow.com/questions/100003/… and the great answer , whilst its about metaclasses it details types and objects to build up the description of a metaclass - really good read.

2018年08月22日18分23秒

Such an awesome question. I've been trying teach my self OOP in Python (my only language), grappling with using inheritance and calling superclass methods. I read that explanation about super had the same question.

2018年08月22日18分23秒

Is super a way to help with Memoization of function calls? I have an object that speeds up calls to another interpreter by checking for the functions existence and then assigning an attribute on the object with an object that directly calls the function. So I basically only lookup the function once and memoize it to a callable attribute. I have to use object.__setattr__(self, "attribute", callableObj) in order to keep it from looping/calling my redefinition of "settr". Does super do the same thing?

2018年08月22日18分23秒

Demolishun: Um, no. You use super to get at inherited versions of overridden methods. Check out the docs

2018年08月22日18分23秒

Okay, so it is similar, but it allows for dynamic reference of the base class, but not by name. That is one use case. rhettinger.wordpress.com/2011/05/26/super-considered-super Thanks for the ref.

2018年08月23日18分23秒

I beg to differ w.r.t., it is not limited to builtins. Everyone can and does define their own types.

2018年08月22日18分23秒

smitkpatel, I think you may be thinking about "builtin" types.

2018年08月22日18分23秒

builtin - default potato - potato

2018年08月22日18分23秒