Logging messages with dictionary args in Python 2.4b1 leads to exception

Bengt Richter bokr at oz.net
Fri Oct 22 20:33:32 CEST 2004


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)
>>>
>> 
>> 
>> logging.want? ;-)
>> 
>Wishful thinking :-)
>
>> Well, it was a trivial example. In real use cases, the dict would be a
>> variable rather than a literal. The problem with using kwargs is that
>> it could interfere with keyword arguments passed to the logging method
>> (currently only exc_info, but there may be others in future).
>> 
>
>Indeed, my ignorance of the current API misled me. But *otherwise* it 
>would have been a good idea, no?

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



More information about the Python-list mailing list