Re: dict literals vs dict(**kwds)

2006-05-26 Thread Bruno Desthuilliers
George Sakkis a écrit : > Bruno Desthuilliers wrote: > > >>George Sakkis a écrit : >> >>>The thing is there are four (at least?) ways to get a dict instance: >>> (snip) >>This actually makes 2 (two) ways of creating a dict: >>- the default call to type (ie : dict(...) >>- the syntactic sugar dic

Re: dict literals vs dict(**kwds)

2006-05-26 Thread George Sakkis
Duncan Booth wrote: > George Sakkis wrote: > > > Duncan Booth wrote: > > > >> George Sakkis wrote: > >> > >> > 2) restricting in a more serious sense: the future addition of > >> > optional keyword arguments that affect the dict's behaviour. Google > >> > for "default dict" or "dictionary accumula

Re: dict literals vs dict(**kwds)

2006-05-26 Thread Paul Rubin
Duncan Booth <[EMAIL PROTECTED]> writes: > > d = dict(default=0) > > d['x'] += 3 > > > > more elegant than > > > > d = {} > > d.withdefault(0) > > d['x'] += 3 > > > Well you could have: > > d = dict.withdefault(0) > > but then you may have to start with an empty dictionary. What happens if >

Re: dict literals vs dict(**kwds)

2006-05-26 Thread Duncan Booth
George Sakkis wrote: > Duncan Booth wrote: > >> George Sakkis wrote: >> >> > 2) restricting in a more serious sense: the future addition of >> > optional keyword arguments that affect the dict's behaviour. Google >> > for "default dict" or "dictionary accumulator". >> >> There is nothing to stop

Re: dict literals vs dict(**kwds)

2006-05-26 Thread George Sakkis
Bruno Desthuilliers wrote: > George Sakkis a écrit : > > The thing is there are four (at least?) ways to get a dict instance: > > > > In [1]: d1={'name':'mike', 'age':23} > > > > In [2]: d2=dict(d1) > > > > In [3]: d3=dict(**d1) > > > > In [4]: d4=dict(d1.items()) > > > > In [5]: d1==d2==d3==d4 >

Re: dict literals vs dict(**kwds)

2006-05-26 Thread Bruno Desthuilliers
George Sakkis a écrit : > bruno de chez modulix en face wrote: > > >>>and there's no compelling reason for dict(**kwds). >> >>Yes there is : this *is* the ordinary Python syntax - calling a type to >>get an instance of it. The dict-litteral syntax is mostly syntactic >>sugar. > > > The thing i

Re: dict literals vs dict(**kwds)

2006-05-26 Thread George Sakkis
Duncan Booth wrote: > George Sakkis wrote: > > > 2) restricting in a more serious sense: the future addition of optional > > keyword arguments that affect the dict's behaviour. Google for "default > > dict" or "dictionary accumulator". > > There is nothing to stop dictionaries being created using

Re: dict literals vs dict(**kwds)

2006-05-26 Thread Duncan Booth
George Sakkis wrote: > Perhaps you fail to understand that the given feature is > 1) redundant (see above). Yes, but a certain degree of redundancy in the language is inevitable, and when it exists (as in this case) to make people's life easier it may be a good thing. Obviously the tradeoff bet

Re: dict literals vs dict(**kwds)

2006-05-26 Thread George Sakkis
bruno de chez modulix en face wrote: > > and there's no compelling reason for dict(**kwds). > > Yes there is : this *is* the ordinary Python syntax - calling a type to > get an instance of it. The dict-litteral syntax is mostly syntactic > sugar. The thing is there are four (at least?) ways to g

Re: dict literals vs dict(**kwds)

2006-05-26 Thread bruno de chez modulix en face
> Hm, as far as I know shadowing the builtins is discouraged. *accidentally* shadowing builtins is a common Python gotcha - that's why it's comon here to raise *warnings* about this. Explicitly and knowingly rebinding a builtin (or any other name FWIW) *with a compatible object* is something else

Re: dict literals vs dict(**kwds)

2006-05-24 Thread George Sakkis
bruno at modulix wrote: > When all your keys are valid Python identifiers, and you may want to use > another dict-like instead of the builtin dict. It's easy to replace the > dict() factory in a function, class, or whole module : > > class MyDict(...): > # dict-like class > > dict = MyDict > > t

Re: dict literals vs dict(**kwds)

2006-05-24 Thread bruno at modulix
George Sakkis wrote: > Bruno Desthuilliers wrote: > > >>George Sakkis a écrit : >> >>>Although I consider dict(**kwds) as one of the few unfortunate design >>>choices in python since it prevents the future addition of useful >>>keyword arguments (e.g a default value or an orderby function), I've

Re: dict literals vs dict(**kwds)

2006-05-23 Thread Alex Martelli
George Sakkis <[EMAIL PROTECTED]> wrote: > Bruno Desthuilliers wrote: > > > George Sakkis a écrit : > > > Although I consider dict(**kwds) as one of the few unfortunate design > > > choices in python since it prevents the future addition of useful > > > keyword arguments (e.g a default value or a

Re: dict literals vs dict(**kwds)

2006-05-23 Thread George Sakkis
Bruno Desthuilliers wrote: > George Sakkis a écrit : > > Although I consider dict(**kwds) as one of the few unfortunate design > > choices in python since it prevents the future addition of useful > > keyword arguments (e.g a default value or an orderby function), I've > > been finding myself late

Re: dict literals vs dict(**kwds)

2006-05-23 Thread Bruno Desthuilliers
George Sakkis a écrit : > Although I consider dict(**kwds) as one of the few unfortunate design > choices in python since it prevents the future addition of useful > keyword arguments (e.g a default value or an orderby function), I've > been finding myself lately using it sometimes instead of dict

dict literals vs dict(**kwds)

2006-05-23 Thread George Sakkis
Although I consider dict(**kwds) as one of the few unfortunate design choices in python since it prevents the future addition of useful keyword arguments (e.g a default value or an orderby function), I've been finding myself lately using it sometimes instead of dict literals, for no particular reas