Long strings as function parameters

Dan Bishop danb_83 at yahoo.com
Sun Jan 9 12:05:25 EST 2005


onlyonemc at gmail.com wrote:
> I would like to have functions that operate on long strings, 10-100
MB.
> In C I would of course pass a pointer to the string for a quick
> function call.  What is an efficient way to do this in python?
> Cheers,

In Python, *every* expression is a pointer.  This fact is clearest when
you look a C-implemented Python functions (which have parameter types
and return types of PyObject*), or when using mutable types.

>>> class Spam:
...    def __init__(self):
...       self.foo = 0
...
>>> x = Spam()
>>> y = x
>>> y.foo = 17
>>> x.foo
17

Compare this to the C code:

typedef struct {int foo;} Spam;
...
Spam *x, *y;
...
y = x;
y->foo = 17;
printf("%d\n", x->foo);




More information about the Python-list mailing list