C pointers/Python

Stephen Thorne stephen.thorne at gmail.com
Mon Mar 21 20:10:00 EST 2005


On 21 Mar 2005 15:52:44 -0800, joe at gmail.com <doodle4 at gmail.com> wrote:
> Hello,
> 
> I am trying to convert some C code into python.
> Here's the C code...
> 
> typedef enum {
> CODE1 = 0x1,
> CODE2 = 0x2
> } CODE
> testit(unsigned char *buffer,
>        unsigned long length,
>        CODE code)
> {
>     unsigned long data
>     switch (code)
>     {
>       case CODE1:
>       while(len--)
>       {
>           *buffer++ = (unsigned long)data++
>       }
>       break

CODE1 = 1
CODE2 = 2
def testit(code):
    data = 'somedata'
    if code == CODE1:
        return data

In C, you pass a memory location to copy the result into. In Python,
we return the result as an object.

As for pointers, we don't need them.

-- 
Stephen Thorne
Development Engineer, NetBoxBlue.com



More information about the Python-list mailing list