if foo.__class__ == Foo: #in C? 
Author Message
 if foo.__class__ == Foo: #in C?

  Perhaps some kind python expert could help me out.  What I am trying
to do is find a way to do the following using Pythons extension
interface in C.

class Foo:
    def __init__(self):
        print "Hello"

foo = Foo()

# This is the bit I want to do in C.
if foo.__class__ == Foo:
    print "It is a Foo"

  So far my attempt looks like this:

PyObject *o;      // a python object.
PyObject *module; // a python module that defines the class Foo

...

PyObject *pyClass = PyObject_GetAttrString(module, "Foo");
PyObject *oclass = PyObject_GetAttrString(o, "__class__");

if (PyObject_Compare(oclass, pyClass))
    printf("It is a Foo\n");

  So far my efforts have not been a complete success.
PyObject_Compare() seems to always return true.  Of course my
understanding of exactly what this function does is not very good.
So, is there anyone out there that knows how to do this?

Thanks,




Mon, 03 Jan 2000 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. A use for "foo = foo()"

2. foo.py vs. foo.pyc

3. Difference between $foo and [set foo]

4. eval $foo - does $foo get bytecompiled?

5. $foo == "" or [llength $foo] == 0

6. difference between ::foo::woof and foo::woof?

7. Date format from [file atime/mtime foo.foo]

8. class Foo does not call Class.new?

9. Dpulicating "class Foo:" in C

10. 'foo' = #foo -> true or false?

11. %w(foo) v.s. ['foo']

12. "import foo" and "from foo import bar"

 

 
Powered by phpBB® Forum Software