Use open(file, mode)
for files.
The mode is a variant of 'r' for read, 'w' for write, and possibly 'b' appended (e.g., 'rb') to open binary files. See the link below.
Use open
with readline()
or readlines()
. The former will return a line at a time, while the latter returns a list of the lines.
Use split(delimiter)
to split on the comma.
Lastly, you need to cast each item to an integer: int(foo)
. You'll probably want to surround your cast with a try block followed by except ValueError
as in the link below.
You can also use 'multiple assignment' to assign a and b at once:
>>>a, b = map(int, "2342342,2234234".split(","))
>>>print a
2342342
>>>type(a)
<type 'int'>
python io docs
python casting