> If i input the following in python:
>    var1 = 7
>    var2 = 9
>    var3 = 5
>    args = [var1, var2, var3]
>    args.sort()
>
> then if if type:
>
>    args
>
> the output is
>
>    [5, 7, 9]
>
> but i want the output to be
>
>    [var3, var1, var2]
>
> is there a function that will output the variable
> names in the order they have been sorted instead of
> the variable contents themselves?


Hm, I don't know directly how to get the name of a variable. I'd  
hoped there was a private method (var3.__<something>__), but looks  
like there isn't it.

Perhaps you can do something with a dictionary, eval and/or map? Not  
sure how that would work out, you'll have to play around a bit to get  
it working.

But I'm not really sure why you'd want to pass the variable names to  
a function; in the end, you're going to use the actual values anyway,  
not their names, right?


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to