Creating Class Objects in Loop
D'Arcy J.M. Cain
darcy at druid.net
Mon Mar 31 11:51:46 EDT 2008
On Sun, 30 Mar 2008 21:34:00 -0700
John Nagle <nagle at animats.com> wrote:
> What's actually happening to you is that you've run into one of the
> dumber features of Python - default values for parameters which are
> mutable, like lists, result in rather unexpected behavior. The
> problem is that
>
> def __init__(self, pcap = None, sids = []):
I have never liked using that form for different reasons so I never
tripped over that. Now I have another reason to avoid it. It's not a
huge deal to do this.
def __init__(self, pcap = None, sids = None):
if sids is None: sids = []
--
D'Arcy J.M. Cain <darcy at druid.net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
More information about the Python-list
mailing list