Linked Questions

161 votes
2 answers
12k views

Is there a way to trigger code when my class is subclassed? class SuperClass: def triggered_routine(subclass): print("was subclassed by " + subclass.__name__) ...
mic_e's user avatar
  • 5,870
96 votes
1 answer
31k views

I have some confusion regarding meta-classes. With inheritance class AttributeInitType(object): def __init__(self,**kwargs): for name, value in kwargs.items(): setattr(self, ...
Nikhil Rupanawar's user avatar
40 votes
2 answers
4k views

This might be too much of an open ended question, but I'm just now learning about metaclasses in Python and I don't understand how a metaclass is any different than just having a child class inherit ...
user2897013's user avatar
29 votes
3 answers
10k views

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, ...
claudio's user avatar
  • 1,574
15 votes
2 answers
3k views

I have a rough idea of what meta-classes are. They are the classes of which class objects are based on (because classes are objects in Python). But could someone explain (with code) how one goes about ...
Tristan Pops Kildaire's user avatar
37 votes
1 answer
795 views

I know we can overload behavior of instances of a class, e.g. - class Sample(object): pass s = Sample() print s <__main__.Sample object at 0x026277D0> print Sample <class '__main__.Sample'&...
AlokThakur's user avatar
  • 3,761
2 votes
1 answer
16k views

I don't know what does super().__init__(*args, **kwargs) do here. class B(type): def __init__(self, *args, **kwargs): self.a = 'a' super().__init__(*args, **kwargs) class A(...
showkey's user avatar
  • 375
12 votes
0 answers
8k views

I read two articles about Metaclassing in python: What is a metaclass in Python? http://jakevdp.github.io/blog/2012/12/01/a-primer-on-python-metaclasses/ And I read about the ABC(abstract base ...
arthas_dk's user avatar
  • 443
4 votes
1 answer
730 views

Use of isinstance() changed the class type of dict Why is this happening? I know using builtins would prevent but I want to understand better why this is happening. 250 def printPretty(records,...
user113411's user avatar
10 votes
0 answers
531 views

Open a python shell on your django project root with python manage.py shell and observe the following: >>> class A(object): pass #checking type of user-defined class ... >>> type(A) ...
galarant's user avatar
  • 2,027
0 votes
1 answer
372 views

I have the following Python code: class Singleton(type): _instances = {} def __call__(cls, *args, **kwargs): if cls not in cls._instances: cls._instances[cls] = super(...
dave's user avatar
  • 1,241
8 votes
0 answers
269 views

Based on my limited Python knowledge Metaclass is another class. In the following example I am just building a metaclass. Here I overloaded the __new__ method. My expectation is at the end of the ...
py2016's user avatar
  • 81
6 votes
0 answers
170 views

Instances are objects created from classes. Classes are objects too, but created from metaclasses. Functions are objects, methods are objects, files are objects, everything in Python is an object. ...
Alex's user avatar
  • 67
-3 votes
2 answers
79 views

I am trying to use https://github.com/iandees/mongosm/blob/master/insert_osm_data.py this package. It seems like it is written in Python2. I have converted all the way to next(context). However, I am ...
chichi's user avatar
  • 3,330
0 votes
1 answer
63 views

When browsing the source code for the django_filters library, I found a class declaration syntax that I've never seen before: inheritance with arguments. I could not find an explanation in the ...
NFern's user avatar
  • 2,046

15 30 50 per page
1
2 3 4 5
24