Extending the dict class

Bruno Desthuilliers onurb at xiludom.gro
Tue Aug 29 08:21:17 EDT 2006


chosechu wrote:
> Hello Pythoneers:
> 
> I need to pass a list of named arguments to a function in a given
> order,
> and make sure these named arguments are retrieved using keys() in the
> same order they were given. Example:
> 
> keyargs={}
> keyargs['one']=1
> keyargs['two']=2
> keyargs['three']=3
> 
> myfunc(**keyargs)
> -> myfunc would retrieve key arguments with keys() in the same order
> as they were set, i.e. keyargs.keys() == ['one', 'two', 'three']

I'm not sure to understand why you want to do so - perhaps you could
tell more about your real use case ?

Anyway, and since it's not directly possible, a possible workaround
could be to pass a sequence of (key, value) tuples instead (possibly as
*args). This of course requires that you can modify the implementation
of myfunc().


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list