[Python-3000] Proposed changes to PEP3101 advanced string formatting -- please discuss and vote!
Talin
talin at acm.org
Wed Mar 14 07:08:27 CET 2007
Patrick Maupin wrote:
> Ian Bicking actually suggested 'somestring'.eval() for this
> functionality. I like that a lot, in the sense that it gives the same
> sense of danger as eval('somestring'), but at the same time, I dislike
> it intensely because eval('somestring') and 'somestring'.eval() appear
> so similar but would give such drastically different results.
Then I would call that 'somestring'.expand(), or perhaps 'substitute' or
'interpolate' - implying that you are doing an expansion of the named
fields within the current scope.
> If the default usage of locals() / globals() is really that
> objectionable, we can certainly take it out. In that case, I would
> suggest that one possible thing to do is:
>
> 1) Make calling format() with no variables raise an exception; and
> 2) Monitor the usage and see how often people do
>
> 'somestring'.format(namespace=locals()) or
> 'somestring'.format(namespace=(locals(), globals))
>
> If the number of times this extra boilerplate appears in code seems
> excessive, then we could either add another method to do the automatic
> locals() and globals(), or (since we would know there are no uses of
> format() with no variables in the code) reenable the functionality.
More information about the Python-3000
mailing list