for line in sys.stdin: for var in line.split(): #If you need something other than a string you'll need to convert it in a separate step: var = int(var)