replacing all 'rng's in a buffer with consecutive r[1], r[2]'s

Paul McGuire ptmcg at austin.rr._bogus_.com
Wed Oct 4 09:02:06 EDT 2006


"m g william" <mgbg25171 at blueyonder.co.uk> wrote in message 
news:mailman.1253.1159962380.10491.python-list at python.org...
<snip>
> #now replace all 'rng's with consecutive streams
> #===============================================
> def static_num():
>    ''' this is a generator function that avoids globals
> yield differentiates fn as generator fn which freezes
> '''
>    x = 0
>    while True:
>       x += 1
>       yield str(x)
>
> static = static_num().next

Also, check out itertools.count (one of many tools from the excellent 
itertools module), as in:

    static - itertools.count().next

- no need to roll this function for yourself.  You still need to call it for 
each substitution, though, as described elsewhere.

-- Paul 





More information about the Python-list mailing list