I currently have a text file I am reading from that contains 6 numbers that I need to be able to call individually.
The text file looks like this
11 12 13
21 22 23
So far I've used the following to try to get the correct output with no success.
with open(os.path.join(path,"config.txt"),"r") as config:
mylist = config.read().splitlines()
print mylist
This gives me ['11 12 13', '21 22 23'].
with open(os.path.join(path,"config.txt"),"r") as config:
contents = config.read()
params = re.findall("\d+", contents)
print params
This gives me ['11', '12', '13', '21', '22', '23']
with open(os.path.join(path,"config.txt"),"r") as config:
for line in config:
numbers_float = map(float, line.split())
print numbers_float[0]
This gives me 11.0 21.0
The last method is the closest but gives me both numbers in the first column instead of just one.
Also would I be able to separate the numbers in the text file with commas with the same or better result?
Thanks for any help!