, . , . split(), , :
>>> def winnumber(s):
... parts = s.split('SUCCESS Number of wins : ')
... return (parts[0].strip(), int(parts[1]))
...
>>> winnumber('TheBears SUCCESS Number of wins : 14')
('TheBears', 14)
, (, , ), float() - - int(), .
Change . Obviously, this will only work for single lines - if you call the function in multiple lines, it will give you errors. To process the entire file, I would use map():
>>> map(winnumber, open(filename, 'r'))
[('TheBears', 14), ('OtherTeam', 6)]
Also, I'm not sure about your final use for this code, but it might be easier for you to work with outputs as a dictionary:
>>> dict(map(winnumber, open(filename, 'r')))
{'OtherTeam': 6, 'TheBears': 14}
source
share