How to input an integer tuple from user?

Turns out that int does a pretty good job of stripping whitespace, so there is no need to use strip

tuple(map(int,raw_input().split(',')))

For example:

>>> tuple(map(int,"3,4".split(',')))
(3, 4)
>>> tuple(map(int," 1 , 2 ".split(',')))
(1, 2)

tuple(int(x.strip()) for x in raw_input().split(','))

If you still want the user to be prompted twice etc.

print 'Enter source'
source = sys.stdin.readline().strip()  #strip removes the \n

print 'Enter target'
target = sys.stdin.readline().strip()

myTuple = tuple([int(source), int(target)])

This is probably less pythonic, but more didactic...

Tags:

Python