hasattr() that previously returned "True", returns "False" after code converted into cython

57 Views Asked by At

I create a simple class in python and check whether it has a certain attribute. After hasattr() Return True I try to rewrite it in Cython and but then hasattr() returns False.

Look at this example in python:

class Foo_p:
    def __init__(self, val):
        self.val = val
    def printVal(self):
        print(self.val)

a=Foo_p(5)
print(hasattr(a,"val"))

this example prints "True".

Now I try to rewrite it in Cython:

%load_ext Cython
%%cython
cdef class Foo_c:
    cdef int val

    def __init__(self, int val):
        self.val = val
    def printVal(self):
        print(self.val)

b=Foo_c(5)
print(hasattr(b,"val"))

and now it prints "False"

Does anyone has an idea of what has happend?

0

There are 0 best solutions below