如何用空lin划分文本文件

2024-06-02 08:21:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在文本文件上循环扑克手是由空行划分。 文本文件如下所示:

PokerStars Hand #172075855663: Hold'em No Limit ($0.50/$1.00 USD) - 2017/06/22 0:34:27 CET [2017/06/21 18:34:27 ET] Table 'Parysatis' 6-max Seat #6 is the button Seat 1: AndrVik89 ($114.27 in chips) Seat 2: bumpandrun5 ($112.66 in chips) Seat 3: steelNike ($100 in chips) Seat 4: Johnii141 ($105.20 in chips) Seat 5: PapaGun5286 ($194.78 in chips) Seat 6: VexVictor ($180.95 in chips) AndrVik89: posts small blind $0.50 bumpandrun5: posts big blind $1 * HOLE CARDS Dealt to Johnii141 [Qd Kd] steelNike: folds Johnii141: raises $1.80 to $2.80 PapaGun5286: folds VexVictor: folds AndrVik89: folds bumpandrun5: folds Uncalled bet ($1.80) returned to Johnii141 Johnii141 collected $2.50 from pot Johnii141: doesn't show hand SUMMARY * Total pot $2.50 | Rake $0 Seat 1: AndrVik89 (small blind) folded before Flop Seat 2: bumpandrun5 (big blind) folded before Flop Seat 3: steelNike folded before Flop (didn't bet) Seat 4: Johnii141 collected ($2.50) Seat 5: PapaGun5286 folded before Flop (didn't bet) Seat 6: VexVictor (button) folded before Flop (didn't bet)

PokerStars Hand #172076017834: Hold'em No Limit ($0.50/$1.00 USD) - 2017/06/22 0:38:49 CET [2017/06/21 18:38:49 ET] Table 'Parysatis' 6-max Seat #5 is the button Seat 1: AndrVik89 ($122.85 in chips) Seat 2: bumpandrun5 ($141.38 in chips) Seat 4: Johnii141 ($102.20 in chips) Seat 5: PapaGun5286 ($166.14 in chips) Seat 6: VexVictor ($171.45 in chips) VexVictor: posts small blind $0.50 AndrVik89: posts big blind $1 l xFlake l: sits out * HOLE CARDS Dealt to Johnii141 [9h Ks] bumpandrun5: calls $1 Johnii141: folds PapaGun5286: raises $3.15 to $4.15 VexVictor: folds AndrVik89: folds bumpandrun5: calls $3.15 FLOP [2h 3d Jd] bumpandrun5: bets $4.66 PapaGun5286: calls $4.66 TURN [2h 3d Jd] [5h] bumpandrun5: bets $9.08 PapaGun5286: calls $9.08 RIVER [2h 3d Jd 5h] [2s] bumpandrun5: checks PapaGun5286: bets $10 bumpandrun5: folds Uncalled bet ($10) returned to PapaGun5286 PapaGun5286 collected $35.42 from pot PapaGun5286: doesn't show hand SUMMARY * Total pot $37.28 | Rake $1.86 Board [2h 3d Jd 5h 2s] Seat 1: AndrVik89 (big blind) folded before Flop Seat 2: bumpandrun5 folded on the River Seat 4: Johnii141 folded before Flop (didn't bet) Seat 5: PapaGun5286 (button) collected ($35.42) Seat 6: VexVictor (small blind) folded before Flop

*总结*-失败(没有下注)之后,我们有了另一个扑克手。你知道吗

我想做的是从第一手资料中得到我需要的所有信息,然后到下一手资料中得到同样的信息。手被空线分开。 然后把它放到数据帧。你知道吗

我已经做了:

file = open(r'C:\Users\AdamPer\Desktop\Magisterka\2rece.txt','r')
linia = [i.rstrip('\n') for i in file]

import re

pattern_hand = re.compile(r'#(\d+):')
pattern_sb = re.compile('\$(\d+.\d+)/')
pattern_table = re.compile('(Table)\s\'(\w+)(\')')
pattern_seat = re.compile('Seat\s(\d):')
Hand_id = []
sb = [] 
table = []
nr_of_player = []                        
for i in range(len(linia)):
    matches_hand = pattern_hand.finditer(linia[i])
    for match_hand in matches_hand:
        Hand_id.append(match_hand.group(1))
    matches_sb = pattern_sb.finditer(linia[i])
    for match_sb in matches_sb:
        sb.append(match_sb.group(1))
    matches_table = pattern_table.finditer(linia[i])
    for match_table in matches_table:
        table.append(match_table.group(2))
    matches_nr_of_player = pattern_seat.finditer(linia[i])
    for match_nr_of_player in matches_nr_of_player:
        nr_of_player.append(match_nr_of_player.group(1))

print(Hand_id)
print(sb)
print(table)
print(nr_of_player)

玩家列表的编号不正确。我需要的是检查有多少座位是由球员之间的线和存储它作为数字。 行:'表'Parysatis'6-max Seat#6是按钮' 和 行:“AndrVik89:贴小盲0.50美元”

我的目标是获取数据帧like this 我有成千上万个这样的文本文件。你知道吗


Tags: intablesbhandblindbeforeseatchips