[Tutor] Python Extensions in C

James Reynolds eire1130 at gmail.com
Thu May 26 21:34:06 CEST 2011


On Thu, May 26, 2011 at 3:07 PM, Stefan Behnel <stefan_ml at behnel.de> wrote:

> Stefan Behnel, 26.05.2011 18:10:
>
>  James Reynolds, 26.05.2011 17:22:
>>
>>> As an intellectual exercise, I wanted to try my hand at writing some
>>> extensions in C.
>>>
>>
>> This is fine for en exercise, and I hope you had fun doing this.
>>
>> However, for real code, I suggest you use Cython instead. Your module
>> would
>> have been substantially simpler and likely also faster.
>>
>> http://cython.org
>>
>
> Oh, and one more thing: it makes it easier to write safe, portable and
> versatile code. As others have pointed out, your code has unnecessary bugs.
> It also doesn't compile in Python 3 and lacks the ability to calculate the
> averages of a set or deque, for example. Instead, it only handles tuples and
> lists. That reduces the usefulness of your implementation.
>
>
> Stefan
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>


Stefan,

Thank you for point out the above. Could you kindly please point out some of
those unnecessary bugs?

I'm not sure that it matters that it won't work in sets and deque's, so long
as the documentation is clear, no? (Which I'm still not sure how to do, just
yet)

But, I did test it for sets and deque and it works just fine.

setx = set([])
print type(setx)
for i in r:
    setx.add(random.choice(r))
print stats.mean(setx)
dequex = deque([])
print type(dequex)
for i in r:
    dequex.append(random.choice(r))
print stats.mean(dequex)

I'll see what I can do about making it work with P3k, I think the only thing
that would need to be changed would be "PyMODINIT_FUNC initstats(void)" I
believe. Please correct me if I'm wrong though.

Thank you again for the feedback.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110526/0a781f0e/attachment.html>


More information about the Tutor mailing list