PyObject *data - access to raw data?

Thomas Gagne tgagne at ix.netcom.com
Mon Aug 7 21:07:22 EDT 2000


Donn Cave wrote:

> <snip>Anything else you want to send, the basic idea is that you should
> call on it to represent itself as text.  This marshalling business
> is potentially tricky, and there is already lots of good work done
> so you don't have to go there yourself.  I would say look at "struct"
> first, which works with plain data but is limited to machine data
> types, and pickle, which handles complex objects and includes its
> own unpacking instructions in the data.  Whether you use an existing
> marshalling function or not, your approach will end up looking at
> least superficially similar.

Am I to assume then Python programmers would call a network write routine with an
object representing itself as text, so I could safely use PyArg_ParseTuple looking
for strings?  In the C API, a programmer can call the function with a (void *) and
a len, and the send() function dutifully sends it across.  I'm unsure from reading
the response how exactly this would work in Python.

> <snip>
> You don't want to do that, if I understand you right.  Objects should
> be returned literally as the function return value, tuple of objects if
> required.  A function may also modify the contents of a list or dictionary,
> but that would be pretty unusual for a library routine.  Basically you
> can't know what the programmer expects to get back.

If a Python module wants to send a C-like structure to another program written in a
a different language (binary representation aside - assume they've already
considered it) how then would I access the data of, say, the struct?  Hmm.  I'll
take a look at the struct module to see if that answers my question.




More information about the Python-list mailing list