[Pyrex] Re: C-methods in extension types

Helmut Jarausch jarausch at skynet.be
Tue Feb 21 18:48:36 CET 2006


On 21 Feb, Lenard Lindstrom wrote:
> Or just call est_mtdb_get_doc directly from within __new__. If there 
> is more than one way to set the doc attribute then factory functions 
> can be used:
> 
> def DocumentFromId(int id):
>     cdef Document d
>     d = Document()
>     d.doc = est_mtdb_get_doc(id)
>     return d
> 

Many thanks.
This solution is not ideal since the functionality
which creates this Document (est_mtdb_get_doc)
belongs to a different (Database) class.

So I've experimented with a 'cdef'ed member of class
Document like

cdef class Document:

  cdef ESTDOC *doc

  def __new__(self,Void=False) :
    if  Void :  pass
    else :
      self.doc = est_doc_new()  # this is defined elsewhere

and then in the other class

  New_Doc= Document(Void=True)
  Document.set_doc(New_Doc,doc)
  return New_Doc

This leads to a question about 'cdef'ed methods,
please see my other mail

Helmut

-- 
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany



More information about the Pyrex mailing list