So if I have a class like:
CustomVal
I want to be able to represent a literal value, so like setting it in the constructor:
val = CustomVal ( 5 ) val.SomeDefaultIntMethod
Basically I want the CustomVal to represent whatever is specified in the constructor.
I am not talking about custom methods that know how to deal with CustomVal, but rather making it another value that I need.
Is this possible?
Btw 5 is just an example, in reality it’s a custom COM type that I want to instance easily.
So by referencing CustomVal, I will have access to int related functionality (for 5), or the functionality of the object that I want to represent (for COM).
So if the COM object is RasterizedImage, then I will have access to its methods directly:
CustomVal.Raster () ...
EDIT: This is what I mean: I don’t want to access as an attribute, but the object itself:
CustomVal
instead of:
CustomVal.SomeAttribute
The reason I want this is because, the COM object is too involved to initialize and by doing it this way, it will look like the original internal implementation that app offers.
The usual way to wrap an object in Python is to override
__getattr__in your class:So then you can do
You can also override
__setattr__and__delattr__to enable setting and deleting attributes, respectively (see the Python library documentation).