Large integers from C
niemeyer at conectiva.com
Wed Feb 20 19:36:52 CET 2002
> I need to create Large (>300 bit) python Long's from C. I don't need (and
> in fact, don't want) to use the features of the (apparently obselete?)
> mpz module, or gmpy, or whatever. I simply want to say:
> val = PyLong_FromOctets(char *v, int vlen);
You're probably looking for PyLong_FromString().
> intval = reduce(lambda x,y: (x<<8)+ord(y), strval)
> I've tried, and this was too slow (the whole point of the C module being
> to speed this up).
Please, have in mind that this is mostly what long(str, base) does, so
you're not going to have great performance improvements by using it
instead of the python equivalent.
[ 2AAC 7928 0FBF 0299 5EB5 60E2 2253 B29A 6664 3A0C ]
More information about the Python-list