python extension problem (newbie)

Douglas du Boulay ddb at crystal.uwa.edu.au
Tue Jun 1 21:57:57 EDT 1999


Hi ,

I've been trying to write a python extension in C to interface to a
Fortran program
and a class wrapper for the extension using the following code loosely
adapted from Mark Lutz's Programming Python  stackmodule example.

Unfortunately whereas his example works fine, mine goes into a recursive
loop whenever an
instance is instantiated.  It seems that the __getattr__  method of the
wrapper class
cannot find the getattr method of the extension library  and defaults to
trying to call itself, infinitely
recursively.

Having spent about 8 hours trying to figure out why, I still have no
idea.
Help!
Thanks

Doug

>>file oograsp.py

import p2fgraspint

class Grasp:
    def __init__(self, start=None):
        self._base = start or p2fgraspint.Grasp()
        print "doing done"                  # which is never executed
    def __getattr__(self, name):
        print "called getattr"              # executed  endlessly
        return getattr( self._base , name)
    def __setattr__(self, name, value):
        return setattr(self._base, name, value)

>> file  http://www.crystal.uwa.edu.au/~ddb/pyextend/p2fgraspint.c

>> file  graspsub.py

#!/usr/bin/env python
import oograsp
x = oograsp.Grasp()


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/19990602/36571375/attachment.html>


More information about the Python-list mailing list