[Python-3000] Updating PEP 3101

Nick Coghlan ncoghlan at gmail.com
Thu May 31 13:52:21 CEST 2007


Talin wrote:
> In the case where you want direct access to global variables, you can 
> make it even more convenient by caching the Formatter:
> 
>      f = Formatter(globals()).format
>      a = 1
>      print(f("The value of a is {a}"))
> 
> (You can't do this with locals() because you can't keep the dict around.)
> 
> My question to the groupmind out there is: Do you find this extra syntax 
> too inconvenient and wordy, or does it seem acceptable?

I like it - even with locals, it works well for multi-line output:

   fmt = Formatter(locals()).format
   print(fmt('Count: {count}'))
   print(fmt('Total: {total}'))
   print(fmt('Average: {avg}'))

(Hmm, the extra parentheses on print statements are annoying me 
already... but I imagine I will get over it :)

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-3000 mailing list