Re: why any( ) instead of firsttrue( ) ?

2010-06-09 Thread danieldelay
Le 09/06/2010 08:54, Raymond Hettinger a écrit : next(ifilter(None, d), False) Good, this is rather short and does the job !... I should try to use more often this itertools module. Thanks Daniel -- http://mail.python.org/mailman/listinfo/python-list

Re: why any( ) instead of firsttrue( ) ?

2010-06-08 Thread danieldelay
Le 09/06/2010 00:24, Ian Kelly a écrit : Because it was designed as a replacement for "reduce(lambda x, y: x or y, iterable)". The problem arises when the iterable is empty. What false value should be returned? If the iterable is a sequence of bools, then None doesn't fit. If the iterable is

why any( ) instead of firsttrue( ) ?

2010-06-08 Thread danieldelay
Hi, I find very useful in python the ability to use a list or number x like a boolean : if x : do something So I don't understand why was introduced the any( ) function defined as : def any(iterable): for element in iterable: if element: return True re

Re: UnboundLocalError: local variable referenced before assignment

2010-06-08 Thread danieldelay
Le 08/06/2010 10:03, ch1zra a écrit : import os, time, re, pyodbc, Image, sys from datetime import datetime, date, time from reportlab.lib.pagesizes import A4 from reportlab.lib.units import cm from reportlab.pdfgen import canvas from reportlab.pdfbase import pdfmetrics from reportlab.pdfbase.ttf

Re: assign class variable in __init__

2010-06-08 Thread danieldelay
you can also use : >>> class A(object): def __init__(self, **args): self.__dict__.update(args) >>> a=A(source='test', length=2) >>> a.source 'test' but this is to be used carefully because mispelling your args somewhere in your program will not raise any error : >>> A(