Salut André,

On 01.08.07, Andre Wobst wrote:
> still, you have different instances in your example. The only problem
> in your example is, that the garbage collector throws away the
> document instance immediately again. Check this out:
> 
>     from pyx import *
> 
>     class slides:
>         def document(self):
>             d = document.document()
>             return d
> 
>     l = []
>     s = slides()
>     for i in range(4):
>         d = s.document()
>         print d
>         l.append(d)
> 
> ... and you'll get diffent instances. Still, you may have some kind of
> a problem ... and there might be bugs. But as far as your example is
> concerned, everything is fine.

You are right. That explains the equal memory addresses. I had,
however the problem that upon writing the second document, the content
of the first was still there. In the meanwhile, I found the reason for
that: the dangerous initialization of empty lists:

  class document:
      def __init__(self, pages=[]):
          self.pages = pages

The first use of this as document.document() and then adding some
pages modifies the standard argument (which was [] initially). All
further instances are then initialized with this nonempty list.

Which solution do you prefer:

  class document:
      def __init__(self, pages=[]):
          self.pages = pages[:]


  class document:
      def __init__(self, pages=None):
          if pages is None:
              self.pages = []
          else:
              self.pages = pages

I will scan through the code to eliminate all other occurrences of
this problem.

Michael.

-- 
Michael Schindler
  Laboratoire de Physico-Chimie Théorique.
  ESPCI. 10 rue Vauquelin, 75231 Paris cedex 05, France.
  Tel: +33 (0)1 40 79 45 97    Fax: +33 (0)1 40 79 47 31
  http:  www.pct.espci.fr/~michael

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
PyX-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyx-user

Reply via email to