Converting to and storing object reference as a string.

Reply

Join Date: Jun 2008
Posts: 11
Reputation: darkMatter2008 is an unknown quantity at this point 
Solved Threads: 0
darkMatter2008 darkMatter2008 is offline Offline
Newbie Poster

Converting to and storing object reference as a string.

 
0
  #1
Jul 30th, 2008
Hi all,

I'm wondering if it is possible to convert an object reference to a string and vica versa?

Thanks
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,046
Reputation: jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough 
Solved Threads: 263
Sponsor
jlm699's Avatar
jlm699 jlm699 is offline Offline
Knows where his Towel is

Re: Converting to and storing object reference as a string.

 
0
  #2
Jul 30th, 2008
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.
1. Use Code Tags.
2. Homework? Show Effort.
3. Keep discussions on the forum: no PMs
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 11
Reputation: darkMatter2008 is an unknown quantity at this point 
Solved Threads: 0
darkMatter2008 darkMatter2008 is offline Offline
Newbie Poster

Re: Converting to and storing object reference as a string.

 
0
  #3
Jul 30th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 63
Reputation: tzushky is an unknown quantity at this point 
Solved Threads: 4
tzushky's Avatar
tzushky tzushky is offline Offline
Junior Poster in Training

Re: Converting to and storing object reference as a string.

 
0
  #4
Jul 31st, 2008
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
Last edited by tzushky; Jul 31st, 2008 at 4:13 am.
--Tzushky
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 11
Reputation: darkMatter2008 is an unknown quantity at this point 
Solved Threads: 0
darkMatter2008 darkMatter2008 is offline Offline
Newbie Poster

Re: Converting to and storing object reference as a string.

 
0
  #5
Jul 31st, 2008
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?
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 901
Reputation: Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough 
Solved Threads: 213
Gribouillis's Avatar
Gribouillis Gribouillis is offline Offline
Posting Shark

Re: Converting to and storing object reference as a string.

 
0
  #6
Jul 31st, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC