[Python-Dev] Re: AlternativeImplementationforPEP292:SimpleString Substitutions

Moore, Paul Paul.Moore at atosorigin.com
Mon Sep 13 16:50:45 CEST 2004


From: Barry Warsaw
> What I was worried about was if you providing 'mapping' positionally,
> and kwds contained a 'mapping' key, you'll get a TypeError.  I'm going
> to change the positional argument to '__mapping' so collisions of that
> kind are less likely, and will document it in libstring.tex.

Can't you do something like

    def substitute(self, *args, **kwds):
        if len(args) > 1:
            raise TypeError # mild hack...
        if len(args) == 1:
            mapping = args[0]
            mapping.update(kwds)
        else:
            mapping = kwds

        # etc...

This avoids the use of a strangely-named positional argument, at the cost
of a check for too many positional arguments (because the interpreter no
longer does it)

Paul.


__________________________________________________________________________
This e-mail and the documents attached are confidential and intended 
solely for the addressee; it may also be privileged. If you receive this 
e-mail in error, please notify the sender immediately and destroy it.
As its integrity cannot be secured on the Internet, the Atos Origin group 
liability cannot be triggered for the message content. Although the 
sender endeavours to maintain a computer virus-free network, the sender 
does not warrant that this transmission is virus-free and will not be 
liable for any damages resulting from any virus transmitted.
__________________________________________________________________________


More information about the Python-Dev mailing list