[Pyrex] cdef class __init__ && mixed used of python and c variables

Test Drive testdrive6 at gmail.com
Wed Aug 23 02:16:20 UTC 2006


Hello everyone,

Please have alook at the following.

pyrex at pyrex ~/code $ pyrexc -v
Pyrex version 0.9.4.1

pyrex at pyrex ~/code $ cat test.pyx
cdef class Test:
        cdef int i
        cdef int y

        def __init__(self,l,k):
                self.i=l
                self.j=k
                self.x=dict()
                self.y=list()

        def pp(self):
                print self.i
                print self.j
                print self.x
                print self.y

pyrex at pyrex ~/code $ python
Python 2.4.3 (#1, Jul 19 2006, 01:52:32)
[GCC 3.4.6 (Gentoo 3.4.6-r2, ssp-3.4.6-1.0, pie-8.7.9)]
Type "help", "copyright", "credits" or "license" for more information.
>>> import test
>>> t=test.Test(1,2)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "test.pyx", line 7, in test.Test.__init__
    self.j=k
AttributeError: 'test.Test' object has no attribute 'j'
>>>

**
if expected? any alternatives to solve this problem. I have tried "cdef
object j", however in that case user will not be able to use the j when user
will create an instance of the object Test.

Thanks in advance
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.copyleft.no/pipermail/pyrex/attachments/20060823/cbeb2931/attachment.html 


More information about the Pyrex mailing list