>> The values of optional arguments are only once evaluated (when Python
>> reads the definition). If you place there mutable objects like e.g. a
>> list most of the time the effect you see is not what you want. So you
>> have to write it a bit different.
>>
>> def __init__(self, q = None):
Dnia niedziela, 25 czerwca 2006 22:45, Bob Gailer napisał:
> To get the behavior I think you want try:
>
> def __init__(self, q = None):
> if not q: q = []
> self.queue = q
I would disagree... This sure works for empty arguments, but:
>>> u = [1,2,3]
>>> a = Queue(u)
>>> b =
--- Karl Pflästerer <[EMAIL PROTECTED]> schrieb:
>
> The values of optional arguments are only once
> evaluated (when Python
> reads the definition). If you place there mutable
> objects like e.g. a
> list most of the time the effect you see is not what
> you want. So you
> have to write it a bi
Barbara Schneider wrote:
> Hello Group, I am puzzled about this: The following
> code implements a simple FIFO object.
>
> class Queue:
> "Implementing a FIFO data structure."
>
> # Methods
> def __init__(self):
> self.queue = []
>
> def emptyP(self):
> return (s
On 25 Jun 2006, [EMAIL PROTECTED] wrote:
[...]
> This code works as intended. Now my idea is to provide
> an optional argument to the constructor. So I change
> it to:
>
> def __init__(self, q =[]):
> self.queue = q
>
> Now, something very strange happens:
>
a = Queue()
b =
Hello Group, I am puzzled about this: The following
code implements a simple FIFO object.
class Queue:
"Implementing a FIFO data structure."
# Methods
def __init__(self):
self.queue = []
def emptyP(self):
return (self.queue == [])
def insert(self, item):