How do I read a formatted file in Python? -


i need read data file formatted so:

jamestown                         20 rocky mountain                    34 illinois st                       28 ball st                           51 tulsa                              7 bowling green                     34 

i need python read 1 line @ time , both team names ("jamestown" , "rocky mountain") , both scores ("20" , "34").

how go doing this? tried making code see if read team name, whatever reason, doesn't work.

onespace = false char in fileline:     if char == ' ':         if onespace:             team1 = team1[:-1]             return         else:             onespace = true             team1 = team1 + char     else:         team1 = team1 + char         onespace = false 

import re ll=[] line in file.readlines():      ll.append(re.findall(r"(.*?)\s{2,}(\d+)",line) print ll 

https://regex101.com/r/wv5tp1/12


Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -