[Python-ideas] string.format() default variable assignment
Jeff Jenkins
jeff at jeffreyjenkins.ca
Fri Mar 1 20:29:59 CET 2013
A friend of mine wrote a library which does this:
https://pypi.python.org/pypi/ScopeFormatter
It's super handy when doing scripting/debugging.
On Fri, Mar 1, 2013 at 1:51 PM, Brett Cannon <brett at python.org> wrote:
>
>
>
> On Fri, Mar 1, 2013 at 11:55 AM, 김용빈 <kybinz at gmail.com> wrote:
>
>> why we bother with '{variable}'.format(variable=variable) ?
>> can we just '{variable}.format()' ?
>>
>
> variable = "Hello, World!"
> print('{variable}'.format_map(locals()))
>
>
>>
>> if variable is exist, then assign it.
>> if variable is not exist, then raise error
>>
>> I am not language expert. so sorry if this is not a good idea, or already
>> discussed.
>>
>
> As Dustin said, Explicit is Better Than Implicit; you don't want a
> variable to accidentally make your string formatting work by luck because
> you forgot to pass in an argument you meant to but just so happened to have
> a variable with the "right" name.
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130301/012ac655/attachment.html>
More information about the Python-ideas
mailing list