"sins" (aka, acknowledged language problems)

Han-Wen Nienhuys hanwen at dokkum.cs.uu.nl
Sun Dec 19 19:40:00 EST 1999


In article <029e01bf4879$72585ee0$f29b12c2 at secret.pythonware.com>,
Fredrik Lundh <fredrik at pythonware.com> wrote:
>> def copy(regex, dict, inp=sys.stdin, oup=sys.stdout):
>>     def repl(match,dict=dict):
>>         return eval(match.group(1),dict)
>>     while 1:
>>         line = inp.readline()
>>         if not line:
>>             break
>>         oup.write(regex.sub(repl,line))
>> 
>> and wonder that *FOUR*-count-em lines of
[..]
>
>import fileinput
>for line in fileinput.input():
>    ...

How about

    def repl(match,dict=dict):
            return eval(match.group(1),dict)
        
    oup.write (re.sub (repl, inp.read()))
-- 

Han-Wen Nienhuys, hanwen at cs.uu.nl ** GNU LilyPond - The Music Typesetter 
      http://www.cs.uu.nl/people/hanwen/lilypond/index.html



More information about the Python-list mailing list