Getting method arguments into a list of key and value pairs
I'm looking to get each of my method parameters into a dictionary or tuple pairs in a list as later the arguments get put through urllib.urlencode
and formed into a POST statement.
I got as far as this from other SO questions
def func(a,b,c,d,e=None,f=None):
values= locals()
data= dict((k,v) for k,v in values.iteritems() if v is not None)
This second line just strips out the optional arguments not used. The problem with this is because I'm using this as POST data later I need the order of the arguments to be maintained.
So is there a similar way of doing the above but I gue开发者_StackOverflowss avoiding the use of dictionaries because they are orderless?
EDIT: I might have just overlooked something completely.. I can send values through POST in any order right?
POST data is treated as unordered 99.99999% of the time (or maybe even more). Don't worry about the ordering.
精彩评论