Re: Changing return of type(obj)
Ken Elkabany schrieb:
I would simply subclass 'int', but this object needs to be general enough to
pretend to be an 'int', 'NoneType', 'str', etc... A long shot: Can I change
the base class on an instance by instance basis depending on the need? Well,
now I can imagine having a class factory that will spawn for me the class
that inherits the correct base type. Any other solutions?
No, it's not possible. The type is an inherent part of an object. Python
looks up methods and other attributes by looking at the type. The method
call obj.method() is implemented as type(obj).method(obj).
Christian
.
Relevant Pages
- Stylistic question about inheritance
... We might imagine various kinds of expressions, ... If I were solving such a problem in C++, I would define a base class for all ... then derive the various kinds of expression classes from that ... there are reasons to have a base class anyway. ... (comp.lang.python) - Re: Dynamically linking to webservice or COM DLL
... I am re- introducing this thread after exploring the Class Factory ... The main reason is ... the COM implementation does not have a common base class. ... (microsoft.public.dotnet.languages.csharp) - Re: Create an object by class Type reference?
... If you want a dynamic growable class factory you can use a type based ... factory that uses reflection or an interface based class factory. ... I have a bunch of object derived from the same base class. ... (microsoft.public.dotnet.languages.csharp) - Re: Dynamically linking to webservice or COM DLL
... For a class factory to work, they don't necessarily have to have the ... They can share the same interface implementation. ... > the base class needs to be the same for both and in my case, ... (microsoft.public.dotnet.languages.csharp) - Re: set a property of inherited class from base class
... Where the property name is "panel1", ... For example, you can have that property virtual/abstract on the base class, ... the reflection overhead. ... I imagine i have to use reflection, ... (microsoft.public.dotnet.languages.csharp) |
|