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?

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to