argument checking before getattr

Benjamin Tai bt98 at doc.ic.ac.uk
Sat Jan 12 18:02:41 CET 2002


Hi,

I am trying to extend a C/C++ object with Python, and wrapped the object
into a class.

>From the Python document, the following is used to dispatch a method
call from a Python object (an instance of class foo), to a function in
the C/C++ extension :

class foo:
      def __getattr__(self,name):
            return getattr(self._base,name)

I have implemented that. The integration of C/C++, the interface and
Python works perfect.



Instead of doing (hiding) argument checking in the interface, now I am
hoping to do some type checking in Python. The following shows what I am
trying to achieve:

class foo:
      def foo_fun(self,args):
            # do some checking on "args"
            return getattr(self._base,"foo_fun")



Instead of return the correct argument, it only returns a trace of the
following trace:
<built-in method foo_fun of foo object at 0x80ef820>

It doesn't work out. Why? Any comments would be appreciated.

Thanks in advance.

Ben







More information about the Python-list mailing list