Logging messages with dictionary args in Python 2.4b1 leads to exception
Steve Holden
steve at holdenweb.com
Sat Oct 23 10:58:14 EDT 2004
Bengt Richter wrote:
> On Fri, 22 Oct 2004 07:52:31 -0400, Steve Holden <steve at holdenweb.com> wrote:
>
>
>>Vinay Sajip wrote:
>>
>>
>>>Steve Holden <steve at holdenweb.com> wrote in message news:<ROXdd.8976$SW3.2862 at fed1read01>...
>>>
>>>
>>>>But how much simpler
>>>>
>>>>logging.want("%(string)s and the %(number)d dwarves",
>>>> string="Snow White", number=7)
[...]
>
>
> Jumping into unknown wider context here, but (as you know, I'm sure)
> as of recent versions you can easily pass a dict arg using keywords:
>
> >>> def foo(*args,**kw): print args, kw
> ...
> >>> foo('here:', dict(string="Snow White", number=7),'<-is a dict', this='is a kwarg')
> ('here:', {'number': 7, 'string': 'Snow White'}, '<-is a dict') {'this': 'is a kwarg'}
> ^__args tuple_________________________________________________^ ^___kw arg___________^
>
> Less confusing perhaps, the dict arg isolated:
>
> >>> dict(string="Snow White", number=7)
> {'number': 7, 'string': 'Snow White'}
>
> Regards,
> Bengt Richter
That strikes me as an acceptable compromise.
regards
Steve
--
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119
More information about the Python-list
mailing list