Export variables

2009-04-21 Thread msolem
Hello,

I want to make a certain subset of public attributes available through
an interface.

The client should not need to know the names of the attributes.

Here is some code with the important parts missing.  Anyone care to
fill in the missing parts?


class C:
def __init__(self):
self.a = 4
self.b = 6
self.c = 8
self._set_vars([self.a, self.b])  # This call might need to be
done differently

def get_vars(self):
# add code here...

def _set_vars(self, vars):
# add code here...


c = C()
print c.get_vars()
c.a = 9
print c.get_vars()


This is the desired output
[4, 6]   # Values of c.a and c.b
[9, 6]   # Values of c.a and c.b

The important part is that the change to c.a is reflected in the call
to get_vars().  get_vars() and _set_vars() might be moved to a base
class,
and therefore should not have attribute names hard coded in them.

I don't have a specific problem that I'm trying to solve.  I would
just like
to know how this sort of thing could be done.

Thanks,
Mike
--
http://mail.python.org/mailman/listinfo/python-list


unpickling a stream

2009-05-26 Thread msolem
Hello,

I want to send a stream of pickled objects over a socket.  Is there a
standard way of ensuring that only complete objects are unpickled on
the receiving side.

client pseudo code:
  loop forever:
receive some bytes on the socket
if we have received a complete pickled object:  <== How is this
done?
  unpickle the object

This isn't for a project, just trying to learn some more about the
pickle module.

Mike
-- 
http://mail.python.org/mailman/listinfo/python-list