我正在尝试获取文件作为输入并搜索特殊字符。我将 from 和 to 键作为输入。如果 to 关键字在下一行,我应该打印直到找到 to 关键字。for line in contents:if line.startswith("*CHI: ") : line = line.strip("*") tokenize = line.split() p.token_filter(tokenize)说我有一个文件: *CHI: (hi) new [/] friend [//] there [/-] [ bch] [ bch ] /[]/ [/=]<new><there>.%mod: hi there.*CHI: <dude><there>*CHI: &=sighs <and instead the> [//] and then the gira?e got it and gave it to the elephant . *CHI: <he> [/] <he> [/] he hold it .*CHI: then [/-] the doctor give the [/] money to the man*CHI: and (i)s then (.) the little (.) gira?e is crying because it (i)s sinking通过使用上面的代码,我得到如下输出:['new', '[/]', 'friend', '[//]', 'there', 'bch', '/[]/']['dude', 'dude']['and', 'and', 'instead', 'the', 'the', '[//]', 'and', 'then', 'the', 'gira?e', 'got', 'it', 'and', 'gave', 'it', 'to', 'the', 'elephant', '.']['he', 'he', '[/]', 'he', 'he', '[/]', 'he', 'hold', 'it', '.']['then', 'the', 'doctor', 'give', 'the', '[/]', 'money', 'to', 'the', 'man']['and', 'then', '(.)', 'the', 'little', '(.)', 'gira?e', 'is', 'crying', 'because', 'it', 'sinking']我的另一个目标是我应该打印 ['new', '[/]', 'friend', '[//]', 'there', 'bch', '/[]/' 'new' 'there' ' .' ]
添加回答
举报
0/150
提交
取消