help in converting c code needed
Jason Orendorff
jason at jorendorff.com
Mon Feb 11 17:15:41 EST 2002
maximilianscherr wrote:
> can anybody help me convert this c code to python:
Well, actually it's C++. And one or two pieces are missing.
But sure.
First, use zlib instead, if you can.
>>> import urllib # ...just so we have something to compress
>>>
>>> data = urllib.__doc__ # a big string to play with
>>> print len(data)
955
>>> zd = data.encode('zlib')
>>> print len(zd)
522
>>> data2 = zd.decode('zlib')
>>> print len(data2)
955
>>> assert data == data2
But if you really have to do this, then you can pretty much
translate this code line-for-line into Python. But many little
changes are needed:
- Turn pointer variables into index variables
- Turn "pdest" into an array, and don't make the user pass you
an empty array as an argument; create one automatically instead.
(By "array", I mean this:
http://www.python.org/doc/current/lib/module-array.html )
- Don't require a src_size argument; you can just do len(src)
- Instead of "--x" you must do "x -= 1"
and so forth.
If you don't know C or C++, you have little chance of getting
it all exactly right. Get a friend to do it. :)
## Jason Orendorff http://www.jorendorff.com/
More information about the Python-list
mailing list