| | |
Converting to and storing object reference as a string.
![]() |
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.
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.
•
•
Join Date: Jun 2008
Posts: 11
Reputation:
Solved Threads: 0
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.
Thanks in advance.
Have a looksee here:
http://docs.python.org/lib/built-in-funcs.html
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':
http://diveintopython.org/power_of_i...n/getattr.html
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:
http://mail.python.org/pipermail/pyt...er/162983.html
http://docs.python.org/lib/built-in-funcs.html
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':
http://diveintopython.org/power_of_i...n/getattr.html
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:
http://mail.python.org/pipermail/pyt...er/162983.html
Last edited by tzushky; Jul 31st, 2008 at 4:13 am.
--Tzushky
![]() |
Other Threads in the Python Forum
- Previous Thread: name not defined error
- Next Thread: Interact with application in Python
| Thread Tools | Search this Thread |
accessdenied advanced aliased argv beginner bits calling casino change command convert count csv cturtle cursor def dictionary digital dynamic dynamically enter event examples external file float format frange function google gui hints homework i/o iframe import input jaunty java keyboard lapse line linux list lists loop microphone mouse movingimageswithpygame multiple newb number numbers obexftp output parameters parsing path port prime programming projects py py2exe pygame pygtk pyopengl python random recursion remote return reverse scrolledtext session signal simple skinning sprite string strings syntax terminal text threading time tkinter tlapse tuple tutorial ubuntu unicode unit urllib urllib2 variable voip web-scrape whileloop wxpython






