I would like to read a 2d array of integers from stdin (or from a file) in Python.

Non-working code:

from StringIO import StringIO
from array import array

# fake stdin
stdin = StringIO("""1 2
3 4
5 6""")

a = array('i')
a.fromstring(stdin.read())

This gives me an error: a.fromstring(stdin.read()) ValueError: string length not a multiple of item size

Edit
Report