Linked Questions
16 questions linked to/from Dynamic inheritance in Python
0
votes
2
answers
111
views
multiple inheritance without defining a class [duplicate]
I'm not sure that's possible, and I'm wondering if that's the way to go, or if there exists a better way of doing that.
I'll create a toy example to expose what I'm looking for.
Suppose I have people ...
user avatar
user23234689
0
votes
1
answer
82
views
Dynamically pick inheritance when instantiating a class? [duplicate]
class classA:
def common(self):
print('A')
class classB:
def common(self):
print('B')
class classC:
def workflow(self):
print('Do something')
self.common()...
1
vote
0
answers
55
views
Python: can I generically combine base class and derived class [duplicate]
Suppose I have a class X and a class Y, is it possible to dynamically define a class that has X as a base, but also methods of Y.
def combiner(base_class, derived_class):
return derived_class(...
559
votes
21
answers
518k
views
Is there a simple, elegant way to define singletons? [duplicate]
There seem to be many ways to define singletons in Python. Is there a consensus opinion on Stack Overflow?
529
votes
15
answers
320k
views
What is memoization and how can I use it in Python?
I just started Python and I've got no idea what memoization is and how to use it. Also, may I have a simplified example?
91
votes
7
answers
60k
views
How to dynamically change base class of instances at runtime?
This article has a snippet showing usage of __bases__ to dynamically change the inheritance hierarchy of some Python code, by adding a class to an existing classes collection of classes from which it ...
5
votes
4
answers
17k
views
Pass a list of strings as parameter of a dependant task in Airflow
I am trying to pass a list of strings from one task to another one via XCom but I do not seem to manage to get the pushed list interpreted back as a list.
For example, when I do this in some function ...
0
votes
2
answers
1k
views
Python- Multiple dynamic inheritance
I'm having trouble with getting multiple dynamic inheritance to work. These examples make the most sense to me(here and here), but there's not enough code in one example for me to really understand ...
4
votes
1
answer
693
views
Wrap an arbitrary class with a new method dynamically
I have a class A.
I have another class B. instances of class B should function exactly like class A, except for one caveat: I want another function available called special_method(self, args, kwargs)
...
1
vote
2
answers
1k
views
Python Dynamic Inheritance and Attributes
I am looking for a solution to allow me to have dynamic inheritance of classes based on certain conditions being met (Python 3.6). Simple enough it seems, but I can't get the attributes of the parent ...
hubbs5's user avatar
- 1,305
1
vote
1
answer
1k
views
dynamic inheritance in Python through a decorator
I found this post where a function is used to inherit from a class:
def get_my_code(base):
class MyCode(base):
def initialize(self):
...
return MyCode
my_code = get_my_code(...
1
vote
0
answers
346
views
adding dynamically a new parent class to an existing object
How can one add dynamically a new parent class in python to an existing object?
class A:
def doA(self): print('A::doA')
class C(A): pass
c = C()
# class 'B' is created after object 'c'
class B:...
2
votes
1
answer
178
views
Dynamic inheritance that is pickleable?
After much searching, the only way I have found to solve my particular problem is to use dynamic inheritance. It is easy enough following the guide from here and a few other SO questions; most table ...
1
vote
1
answer
221
views
Is there a way to create an object with dynamic parentage in python?
The best way to explain this, I guess, is by example. Writing a game, have a parent class for all character classes that establishes the basic methods and values, with a whole horde of child classes ...
0
votes
0
answers
63
views
How to add a base class(/parent class) to a class in python depending on the initialization parameters of the object of the class
Is it possible to choose which base class to inherit from at the time of object creation? Basically, different objects of the same class will make the class inherit from different base classes ...