Вы можете адаптировать следующий прототип, он извлекает всю необходимую информацию из вашего файла.
Единственное, что вам нужно сделать как домашнее задание, - это отобразить его в виде таблицы.
import re
class PockerStarHand:
def __init__(self, handId, date, seats):
self.handId=handId
self.date=date
self.seats=seats
# does not scale, do this on small input files
with open('example_hands.txt','r') as content_file:
content = content_file.read()
chunck = re.findall(ur'^PokerStars\sHand\s#(\d+):.+?-(\s\d{4}\/\d{2}\/\d{2}\s\d{,2}:\d{2}:\d{2}).+\s+Table.+\s+^((?:Seat\s\d:\s\w+\s?\(.+\)\s*)+)',content, re.MULTILINE)
hands = []
for c in chunck:
hands.append(PockerStarHand(c[0],c[1], re.findall(ur'^Seat\s*(\d)\s*\:\s*(\w+)\s*\(([\$\u20AC])(\d+(?:\.\d+)?)',c[2].decode('utf-8') ,re.MULTILINE | re.UNICODE)))
for hand in hands:
print ("ID: " + str(hand.handId))
print ("date: " + str( hand.date))
for s in hand.seats:
print ("seat: " + str(s[0]))
print ("seat text: " + str(s[1]))
print ("seat curr: " + str(s[2].encode('utf-8')))
print ("seat price: " + str(s[3]))
Токовый выход:
ID: 163417399919
date: 2016/12/23 23:48:52
seat: 1
seat text: xxx
seat curr: $
seat price: 200
seat: 2
seat text: yyy
seat curr: $
seat price: 364.58
seat: 3
seat text: zxc
seat curr: $
seat price: 200
seat: 4
seat text: zdf
seat curr: $
seat price: 235.43
seat: 5
seat text: zdasdasII
seat curr: $
seat price: 206.02
seat: 6
seat text: assfds
seat curr: $
seat price: 92.53
ID: 162960631727
date: 2016/12/15 2:10:16
seat: 2
seat text: xxx
seat curr: $
seat price: 137.08
seat: 3
seat text: yyy
seat curr: $
seat price: 200
seat: 5
seat text: xyz
seat curr: $
seat price: 201.20
ID: 163416930846
date: 2016/12/23 23:39:57
seat: 1
seat text: xxx
seat curr: €
seat price: 230.90
seat: 2
seat text: yyy
seat curr: €
seat price: 256.25
seat: 3
seat text: zzz
seat curr: €
seat price: 200
seat: 4
seat text: ddd
seat curr: €
seat price: 200
seat: 5
seat text: ccc
seat curr: €
seat price: 223.40
seat: 6
seat text: fff
seat curr: €
seat price: 77.65
Детали регулярного выражения: