473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

serializable object references

Is it possible to convert an object into a string that identifies the
object in a way, so it can later be looked up by this string.
Technically this should be possible, because things like

<__main__.Foo instance at 0xb7cfb6ac>

say everything about an object. But how can I look up the real object,
when I only have this string?

I know such a thing can be achieved with a dictionary that holds
reference-object pairs. Is there another way?
Apr 22 '07 #1
8 1284

Martin Drautzburg wrote:
Is it possible to convert an object into a string that identifies the
object in a way, so it can later be looked up by this string.
Technically this should be possible, because things like

<__main__.Foo instance at 0xb7cfb6ac>

say everything about an object. But how can I look up the real object,
when I only have this string?

I know such a thing can be achieved with a dictionary that holds
reference-object pairs. Is there another way?
How about:

class Dog(object):
def __init__(self, name):
self.name = name

d = Dog("Spot")
print globals()["d"].name

Apr 22 '07 #2
On Apr 22, 5:07 am, Martin Drautzburg <Martin.Drautzb...@web.de>
wrote:
>
<__main__.Foo instance at 0xb7cfb6ac>

But how can I look up the real object,
when I only have this string?
You can't because that identifies the instance with an address, and
pointers are not part of the python language.

Apr 22 '07 #3
En Sun, 22 Apr 2007 08:07:27 -0300, Martin Drautzburg
<Ma***************@web.deescribió:
Is it possible to convert an object into a string that identifies the
object in a way, so it can later be looked up by this string.
Technically this should be possible, because things like

<__main__.Foo instance at 0xb7cfb6ac>

say everything about an object. But how can I look up the real object,
when I only have this string?

I know such a thing can be achieved with a dictionary that holds
reference-object pairs. Is there another way?
Without further information, this would be the way.
What do you want to achieve? Maybe you are looking for the pickle module.

--
Gabriel Genellina
Apr 22 '07 #4
Is it possible to convert an object into a string that identifies the
object in a way, so it can later be looked up by this string.
Technically this should be possible, because things like

<__main__.Foo instance at 0xb7cfb6ac>

say everything about an object. But how can I look up the real object,
when I only have this string?

I know such a thing can be achieved with a dictionary that holds
reference-object pairs. Is there another way?

There is the pickle module for serializing objects into strings:
http://docs.python.org/lib/module-pickle.html

If you need to store objects and later look them up by some key I
would recommend using a database. There are plenty:
http://docs.python.org/lib/persistence.html

HTH,
Daniel
Apr 22 '07 #5
Gabriel Genellina wrote:
En Sun, 22 Apr 2007 08:07:27 -0300, Martin Drautzburg
<Ma***************@web.deescribió:
>Is it possible to convert an object into a string that identifies the
object in a way, so it can later be looked up by this string.
Technically this should be possible, because things like

<__main__.Foo instance at 0xb7cfb6ac>

say everything about an object. But how can I look up the real
object, when I only have this string?

I know such a thing can be achieved with a dictionary that holds
reference-object pairs. Is there another way?

Without further information, this would be the way.
What do you want to achieve? Maybe you are looking for the pickle
module.
I was thinking that it would be nice if a web application could talk to
real objects. The client side does not need to know the internals of an
object, it acts as a "view" for server-side models. All it has to be
able to do is invoke methods on "its" model. So a view could just
store "its" object-reference in an instance variable and pass it to the
server, where my problem of looking it up comes in.

I am currently learning about web services but my feeling is
that "state" is not an integral part of this concept, rather an add-on,
but I may be mistaken here.

But for any reasonable web application you have to introduce state one
way or the other. My impression is, that this is achieved with "session
objects", which hold all the state of a session (again I may be
mistaken). But this would be a strange concept in an OO world. You
might as well put "ALL" state into a global "state" state object, where
all the class methods deposit their state and classes would hold
behavior only and no state. This is of course nothing an OO programmer
would want to do.


Apr 22 '07 #6
En Sun, 22 Apr 2007 12:47:10 -0300, Martin Drautzburg
<Ma***************@web.deescribió:
I was thinking that it would be nice if a web application could talk to
real objects. The client side does not need to know the internals of an
object, it acts as a "view" for server-side models. All it has to be
able to do is invoke methods on "its" model. So a view could just
store "its" object-reference in an instance variable and pass it to the
server, where my problem of looking it up comes in.
This is more or less what several web frameworks do. You publish objects;
URLs are mapped to method objects; URL parameters become method
parameters. See http://wiki.python.org/moin/WebFrameworks
I am currently learning about web services but my feeling is
that "state" is not an integral part of this concept, rather an add-on,
but I may be mistaken here.

But for any reasonable web application you have to introduce state one
way or the other. My impression is, that this is achieved with "session
objects", which hold all the state of a session (again I may be
mistaken). But this would be a strange concept in an OO world. You
might as well put "ALL" state into a global "state" state object, where
all the class methods deposit their state and classes would hold
behavior only and no state. This is of course nothing an OO programmer
would want to do.
You can have a "persistent" state (stored in a backend database) and
"transitory" state (kept in session objects).

--
Gabriel Genellina
Apr 23 '07 #7
Gabriel Genellina wrote:
En Sun, 22 Apr 2007 12:47:10 -0300, Martin Drautzburg
<Ma***************@web.deescribió:
>I was thinking that it would be nice if a web application could talk
to real objects. The client side does not need to know the internals
of an object, it acts as a "view" for server-side models. All it has
to be able to do is invoke methods on "its" model. So a view could
just store "its" object-reference in an instance variable and pass it
to the server, where my problem of looking it up comes in.

This is more or less what several web frameworks do. You publish
objects; URLs are mapped to method objects; URL parameters become
method parameters. See http://wiki.python.org/moin/WebFrameworks
Okay will look. I have checked out cherrypy, but it does not seem to
support direct object references, i.e. the server-side objects are
really stateless and all calls to an object method will see the same
state unless you do something about it youself.

I have also looked at the wonderful qooxdoo javascript framework and in
the examples they have, the data I receive on a published object method
on my cherrypy server is:
dict: {
'_ScriptTransport_id': '11',
'_ScriptTransport_data': '{
"service":"qooxdoo.test",
"method":"sleep",
"id":13,
"params":["10"],
"server_data":null
}',
'nocache': '1177256001914'
}

I am not sure what all of them mean, but my impression is that none of
them denote an object in the sense of an INSTANCE, at least "service"
and "method" definitely do not. The "id" is simply incremented with
every call, so it is again not an instance.

Now I could of course add an object reference do the "params" field and
have qooxdoo.text dispatch the call to an INSTANCE of an object and
invoke sleep() there. But first it is a shame, that I have to provide
this magic myself, and second it raises again my original question: how
to I pass an object reference and look up the object in qooxdoo.test.

I know I can do this with a dictionary, I just thought that the
__repr__() of an object could be used, as it seems the most obvious way
to do it.
Apr 23 '07 #8
En Mon, 23 Apr 2007 03:35:42 -0300, Martin Drautzburg
<Ma***************@web.deescribió:
Gabriel Genellina wrote:
>En Sun, 22 Apr 2007 12:47:10 -0300, Martin Drautzburg
<Ma***************@web.deescribió:
>>I was thinking that it would be nice if a web application could talk
to real objects. The client side does not need to know the internals
of an object, it acts as a "view" for server-side models. All it has
to be able to do is invoke methods on "its" model. So a view could
just store "its" object-reference in an instance variable and pass it
to the server, where my problem of looking it up comes in.

This is more or less what several web frameworks do. You publish
objects; URLs are mapped to method objects; URL parameters become
method parameters. See http://wiki.python.org/moin/WebFrameworks

Okay will look. I have checked out cherrypy, but it does not seem to
support direct object references, i.e. the server-side objects are
really stateless and all calls to an object method will see the same
state unless you do something about it youself.
The description I wrote above aplies exactly to ZOPE: URLs map exactly to
object methods and those objects can (and should) maintain state. (Zope
uses an OO database, ZODB, to hold those objects).
But Zope is a big framework and not easy to grasp, so I would not recomend
it for a small site or web application.
Using CherryPy you can keep state across requests, if you use some sort of
session machinery; at least you could build a mapping SessionID-State (the
state being as complex as you want).
I think TurboGears has something built in for managing sessions, but I'm
not sure.
I have also looked at the wonderful qooxdoo javascript framework and in
the examples they have, the data I receive on a published object method
on my cherrypy server is:
Never used qooxdoo...

--
Gabriel Genellina
Apr 23 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: xmail123 | last post by:
Hi, As was pointed out whatever you return from a WebMethod needs to be serializable to SOAP. An ArrayList is not serializable. I will be needing to return other data types from web methods. ...
3
by: Raghavendra Tilve | last post by:
Unable to serialize the session state. Please note that non-serializable objects or MarshalByRef objects are not permitted when session state mode is 'StateServer' or 'SQLServer'. Description: An...
1
by: Harshdeep Mehta | last post by:
Hi all, I have written a page in which I want to preserve value of object - suppose A - value, so I used viewstate. but that give me error. Code : ViewState = objClassA; // Before PostBack...
2
by: Frank Uray | last post by:
Hi again I have a little problem with "serializable" a control ... I am creating AppDomain, Assembly and Instance. All works fine. My "base" class for the instance inherit from: -...
1
by: cpnet | last post by:
I have a DataTable defined in a strongly-typed DataSet: public class MyDataSet: DataSet... { ... public class MyDataTable: DataTable... { ...}
3
by: Techno_Dex | last post by:
I'm wanting to create a Wrapper (or Extender depending on how you look at it) for a Serializable object that I then want to send over a webservice. Basically I want to create a Serializable Object,...
8
by: Techno_Dex | last post by:
Has anyone come up with a slick way to make Custom Serializable Objects to behave like DataSets when using WebServices? What I'm looking for is some way to force the WSDL generated code to create...
0
mmfranke
by: mmfranke | last post by:
Hello. Hi. I'm writing a logging service that uses .NET remoting. The idea is that the service publishes an EventProcessor object that clients can access via .NET Remoting, passing it...
2
by: Morten Snedker | last post by:
<Serializable()Public Class Dealer What does Serializable do? Regards /Snedker
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.