[Edu-sig] self within re.sub

Bruno Vernier vernier@vc.bc.ca
Thu, 8 Feb 2001 08:17:11 -0800


On Wed, Feb 07, 2001 at 12:17:08PM -0600, David Niergarth wrote:

> If I understand what your asking... You can pass the rpython instance into
> the replace function as a default argument. For example,
> 
>   text = tag.sub(lambda m, instance=rpython: process(m, instance), text)
> 
> and change process() to expect a second argument. If the instance exists
> before you define process(), you could skip the lambda and define process as
> 
>   def process(match, instance=rpython):
>       # do useful stuff
>       return # evaluated python or latex snippets
> 
>   text = tag.sub(process, text)


Thank you very very much!  It works. :-)  

Bruno