Re: [pyar] ¿If anidado?

Página superior
Adjuntos:
+ (text/plain)

Responder a este mensaje
Autor: Roberto Alsina
Fecha:  
A: pyar
Asunto: Re: [pyar] ¿If anidado?
On Thursday 17 September 2009 13:47:33 guagliap@??? wrote:
> def firstTrue(cond):
> """ devuelve True siempre la primera vez que se la ejecuta, las veces
> subsiguientes evalua la condicion """ stack = inspect.stack()[1] # El
> stack del programa llamador line = stack[2] # Nro de linea
> desde la que llame a firstTrue del stack
>
> if not "line" in firstTrue.__dict__:
> # Primera vez que llamo a la funcion
> firstTrue.line = line
> return True
> elif firstTrue.line != line:
> # Llame a la funcion desde otro punto del programa
> firstTrue.line = line
> return True
>
> return cond


A ver...

def firstTrue():
    yield True
    while True:
        yield False

ft=firstTrue()
print ft.next()
print ft.next()
print ft.next()

Produce

True
False
False

y es un poco más pitónico ;-)
-- 
 ("\''/").__..-''"`-. .         Roberto Alsina
 `9_ 9  )   `-. (    ).`-._.`)  KDE Developer (MFCH)
 (_Y_.)' ._   ) `._`.  " -.-'  http://lateral.netmanagers.com.ar 
  _..`-'_..-_/ /-'_.'     The 6,855th most popular site of Slovenia   
(l)-'' ((i).' ((!.'       according to alexa.com (27/5/2007) 


---------------------------------------------------------------------
Para dar de baja la suscripcion, mande un mensaje a:
   pyar-unsubscribe@???


Para obtener el resto de direcciones-comando, mande un mensaje a:
pyar-help@???

PyAr - Python Argentina - Sitio web: http://www.python.com.ar/