let me re-phrase that question:
i would like to access the element of individual tuples inside of a
list, by using an index.
so i have the list contents

print list
[('--datasourcename', 'DB'), ('--password', '123')]

How can I access "DB" from the list directly using an index?

right now I would have to grab the tuple and the use the index of the tuple

Well, you can use

  lst[0][1]

to get it. Or, if you're parsing through the list, you can use tuple unpacking:

  for name, value in lst:
    print "%s = %s" % (name, value)

As an aside, it looks like you're doing parameter parsing. The standard library has the optparse module which takes a lot of pain out of parsing parameters.

-tkc



--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to