You should not use eval on user input generally. Someone can type a statement that will eval into mischief.
For the same reason, you should avoid the use of input() since it is the equivalent of eval(raw_input())
also can lead to mischief -- intended or not.
You can, however, SAFELY get Python interpretation of user input into Python data structures with ast.literal_eval:
>>> import ast
>>> ast.literal_eval(raw_input('Type Python input: '))
Type Python input: 1,2,3
(1, 2, 3)
>>> ast.literal_eval(raw_input('Type Python input: '))
Type Python input: [1,2,3]
[1, 2, 3]
>>> ast.literal_eval(raw_input('Type Python input: '))
Type Python input: 123
123
>>> ast.literal_eval(raw_input('type a number: '))
type a number: 0xab
171
(In each case, the first line after >>> Type Python input:
is what I typed into the raw_input()
If you want to split digits apart, you can do this:
>>> [int(c) for c in raw_input() if c in '1234567890']
1234
[1, 2, 3, 4]
>>> [int(c) for c in raw_input() if c in '1234567890']
123a45
[1, 2, 3, 4, 5]
Notice the non digit is filtered.