Sunday, October 13, 2013

Reading a single line of numbers from file to a list of floats

Let's say you have a text file that contains a row

23 34 155

and you wish to read this line and then save the three different numbers into three variables a,b and c.
Use the built in map and split functions along with your file read

>>> a,b,c = map(int, open('some_file.txt').read().split())
>>> print a
... 23


No comments:

Post a Comment