8 Years
Discussion Span
Last Post by Gribouillis

Not exactly sure what it is you're looking for. But many built-in objects can have the str() function applied to them with little problem.

If it's a custom class or similar you may need to look into the Pickling module. I don't know if you plan to use the string for something other than storing it on your FS; however here's the documentation.


I'm using a 3D program called blender, for some reason gameobjects objects can only store number type variables, bool and strings. Pickling would not good in this case as it serialises the whole object, and the contents will be no longer be up to date. I've noticed if you use the print command on an object refernce you get the Class type and memory address of it, I was wondering if there was a way to store that in a string, and then turn it back into an object reference when needed.

Thanks in advance.


Have a looksee here:


The id() function and maybe more, didn't have much time to look for more... Maybe the int of the reference is enough, you can definitely turn that into a string and recover your int or whatever you want....

There might also be 'getattr':

Let me know if it's useful...

However, if you would like to retrieve the object with that reference later... I don't quite know how that would work, I read something of a module mxTools , and also found this thread in a forum which looks like the same problem you have:



That certainly is usefull, I can store the reference a int instead of a string, is there anyway of converting that int back into a reference?


A solution is to keep a dictionary of the objects you reference. The dictionary would have the object's id's as keys and the object as values.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.