python - 删除txt文件内所有<>里面的内容包括<>本身。
ringa_lee
ringa_lee 2017-04-18 10:27:36
0
1
774

删除txt文件内所有<>里面的内容包括<>本身。该怎么写?
卡在对字符串的处理那里。

ringa_lee
ringa_lee

ringa_lee

reply all(1)
大家讲道理

Probably like this:

Use re.sub<...> instead of blank:

# python3 code

import re

# for example
s = '123<><here>#$%@#$%^<123>::<a class="haha" href="http://www.hello.com">haha'
print(re.sub('<[^>]*>', '', s))

# read txt and remove all <...>
with open('your.txt', 'r') as reader:
    for line in reader:
        line = line.strip()
        print(re.sub('<[^>]*>', '', line))

Example string replacement result:

123#$%@#$%^::haha

Questions I answered: Python-QA

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template