Michael, On 01.08.07, Michael SCHINDLER wrote: > 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.
Blame on us. Blame ... please ... :-) > 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'm not sure. Personally I somehow favour the second option (which is quite Pythonic btw), but I remember a "bug" Jörg came up with some time ago. It was about an internal reordering of some attributes and it was done on the original list passed to the method. I understand that such a behaviour can be very troublesome and shouldn't be done for such an end-user library like PyX. So let me formulate a rule of thumb: Go for option 1 for all attributes, which are not read-only. (For read-only attribute *no* copy is necessary and should not be made.) Jörg, do you agree? > I will scan through the code to eliminate all other occurrences of > this problem. Thanks a lot! André -- by _ _ _ Dr. André Wobst / \ \ / ) [EMAIL PROTECTED], http://www.wobsta.de/ / _ \ \/\/ / PyX - High quality PostScript and PDF figures (_/ \_)_/\_/ with Python & TeX: visit http://pyx.sourceforge.net/ ------------------------------------------------------------------------- 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
