C pointers/Python
Stephen Thorne
stephen.thorne at gmail.com
Tue Mar 22 19:02:59 EST 2005
On 21 Mar 2005 19:32:20 -0800, joe at gmail.com <doodle4 at gmail.com> wrote:
> Can i do something like this?
>
> if code == CODE1:
> data = 0x0
> While True:
> len = len - 1
> if len == -1:
> break
> buffer = data
>
> Do i need to initialze the buffer?
Please, forget everything you know about memory, pointers, and C idiom.
Also, considering doing the python tutorial. There is one provided
here: http://python.org/doc/tut
Basically, you're not approaching this in a python-like way, and thus
what should be a single line (i.e. 'return data') you're trying to
turn into a painful process of copying data from one memory location
to another. This is acceptable in the C world, and not appropriate in
the python world.
I would suggest you define your problem in broader terms (i.e. "I am
trying to interpret data that is coming over a socket, my packet
structure looks like this ..., how do I marshall dispatch that to
callbacks so I can talk the protocol properly? Here is a link to the
working C code http://...") and there is a large group of wonderful
people here that would love to show you the pythonic way of achieving
your goal.
--
Stephen Thorne
More information about the Python-list
mailing list