On 04/17/2013 08:12 PM, Alan Gauld wrote:
On 17/04/13 20:27, Danilo Chilene wrote:import sys a = 'This is A' b = 'This is B' c = 'This is C' for i in sys.argv[1]: if sys.argv[1] == 'a': print a if sys.argv[1] == 'b': print b if sys.argv[1] == 'c': print c I run python file.py a and returns the var a, so far so good. The problem is that i have a bunch of vars(like a to z), how I can handle this in a pythonic way?Use a dictionary. myVars = { 'a':'This is A', 'b':'This is B', 'c':'This is C', # as many more as needed } print myVars.get(sys.argv[1], 'No variable found') Is that what you mean?
What's the point? The OP is not clarifying the "spec." I posited a dict and supplied code several messages ago (about 4.5 hours), and he said "worked like a charm." But since then he has given cryptic responses to others, and still not answered a few of the questions I asked then.
-- DaveA _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
