I have a class instance I set to a custom property, I had read this wouldn't work but wanted to test it. it saves a string that gives a pointer to a memory address. I was wondering if there is any easy way to access the memory address so I could use the class instance.
Hey Travis,
Even if you could do that, I probably wouldn't.
I would store the __dict__ in a property object and reconstruct it when you need to instantiate the class. This assumes your instance variables are primitives. If you are trying to store a more complex object you can define your own deconstruction. For perspective, the approach below usually fits most use cases.
Example:
class SomeClass(object):
def __init__(self, value1, someValue):
# type: (int, str) -> None
self.value1 = value1
self.someValue = someValue
someClass = SomeClass(1, "hello")
someClass.__dict__
# Using existing properties from perspective
formObjectProperty = {
"value1": 123,
"someValue":"test"
}
anotherClass = SomeClass(**formObjectProperty)
anotherClass.__dict__
Output:
{'value1': 1, 'someValue': 'hello'}
{'value1': 123, 'someValue': 'test'}
Since we haven't yet done this first party, Phil implemented essentially what you're asking for in his integration toolkit module:
Let me clarify that the functions do not make the object at a stringified address accessible. Especially since jython and java do not provide actual addresses in stringification--those are arbitrary identity values.
The Perspective session/page/view functions give you a related dictionary into which you can put arbitrary java/jython objects, and they will not be stringified. And the dictionary will be cleaned up when the session/page/view life cycle ends.