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

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -