Tell me the truth

2007-03-08 Thread francois . petitjean
In the python-ideas mailing list http://mail.python.org/pipermail/python-ideas/2007-March/thread.html there was a discussion about the fact that python has opeartors 'and', 'or' and 'not' (keywords of the language) but 'bool' is a type. Naturally we have (not not x) == bool(x) # always True If

Re: Tell me the truth

2007-03-08 Thread francois . petitjean
Duncan Booth wrote : > francois.petitjean at bureauveritas.com wrote: >> After much head scrating and experimenting with dis.dis() I have found >> that chaining comparisons (with is or ==) a == b == c in Python is >> never a good idea. It is interpreted as >> ( a == b ) and ( b == c) >> Such a m

How to clear a list (3 ways).

2008-03-06 Thread francois . petitjean
Consider the following code : #!/usr/bin/env python # -*- coding: latin_1 -*- """ container.py how to clear a container """ class Container(object): def __init__(self): self.elts = {} self.parts = [] def clear(self): self.elts.clear() # for a dictionary it's cl

How to clear a list (3 ways).

2008-03-07 Thread francois . petitjean
(second try with an enhanced version) Executive summary : What idiom do you use for resetting a list ? lst = |] # (1) lst[:] = [] # (2) del lst[:] # (3) Consider the following code : #!/usr/bin/env python # -*- coding: latin_1 -*- """ container.py how to clear a container """ c