[Tutor] Pass variable on command line
jason
swimlappy at gmail.com
Thu Jul 26 21:41:34 CEST 2007
Ok, I see now. A dictionary using the list elements as values. This will
work for me. Thanks!
jason
On 7/26/07, Eric Brunson <brunson at brunson.com> wrote:
>
> jason wrote:
> > Hello,
> >
> > I have a situation where I have 2 lists
> >
> > List1 = ['blue', 'red', green']
> > List2 = ['red', 'yellow', 'orange']
> >
> > And I would like to pass the list name on the command line like so
> >
> > ./test.py List1
> >
> > I know I can get the argument using sys.argv[1]
> >
> > But how can I then use the values in that list inside my program?
> >
> > If I do a VALUES = sys.argv[1], then I get List1 as the values. I
> > want the actual list elements.\\
>
> The easiest way to do this would be to define your lists in a dictionary:
>
>
> lists = { 'List1': ['blue', 'red', green'], 'List2': ['red', 'yellow',
> 'orange'] }
>
> if len(sys.argv) > 1 and sys.argv[1] in lists:
> VALUES = lists[sys.argv[1]]
>
>
> >
> > Is this possible?
> >
> > Thank you
> >
> > Jason
> >
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Tutor maillist - Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070726/66d8db1f/attachment.htm
More information about the Tutor
mailing list