How do I get user input to refer to a variable in Python?

Posted by somefreakingguy on Stack Overflow See other posts from Stack Overflow or by somefreakingguy
Published on 2010-06-17T02:04:24Z Indexed on 2010/06/17 2:12 UTC
Read the original article Hit count: 297

Filed under:
|
|
|
|

I would like to get user input to refer to some list in my code. I think it's called namespace? So, what would I have to do to this code for me to print whatever the user inputs, supposing they input 'list1' or 'list2'?

list1 = ['cat', 'dog', 'juice']
list2 = ['skunk', 'bats', 'pogo stick']

x = raw_input('which list would you like me to print?')

I plan to have many such lists, so a series of if...then statements seems unruly.

© Stack Overflow or respective owner

Related posts about python

Related posts about beginner