Order of keyword arguments
Emile van Sebille
emile at fenx.com
Mon Nov 22 07:10:47 EST 1999
Andres,
Perhaps you can adapt one of these ideas.
HTH
Emile van Sebille
emile at fenx.com
-------------------
#------start of code fragment
import traceback
def ordered1(opts ,**kws):
print opts
kws = eval('{'+opts+'}')
print kws
def ordered2(opts ,**kws):
print opts
def convert_to_dict(**kws):
return kws
kws = eval('convert_to_dict(' + opts+ ')')
print kws
def ordered3(**kws):
tbs = traceback.extract_stack()
for line in tbs:
if line[3][:8] == 'ordered3':
call_order = line[3][9:]
print call_order
print kws
ordered1 (opts="'c':1, 'b':2, 'a':1")
ordered2 (opts="c=1, b=2, a=1")
ordered3 (c=1, b=2, a=1)
#-------end of code fragment
----- Original Message -----
From: Andres Corrada <andres at corrada.com>
To: <python-list at python.org>
Sent: Saturday, November 20, 1999 10:33 PM
Subject: Order of keyword arguments
> Hi,
> Can one access the order in which keyword arguments were passed to a
> function? I want to call a function with the keyword syntax: f(
> foo='theFooString', bar='theBarString' ) and use the fact that foo was
> listed first so I can do something like:
>
> def f( **kw ):
>
> Process keyword arguments remembering the order in which the were used
> to call the function.
> Print first keyword
> Print second keyword
> .
> .
> .
>
> ------------------------------------------------------
> Andres Corrada-Emmanuel Email: andres at corrada.com
> Owner http://www.corrada.com/mamey
> Mamey Phone: (413) 587-9595
> ------------------------------------------------------
>
> --
> http://www.python.org/mailman/listinfo/python-list
>
>
More information about the Python-list
mailing list