Python 删除所有<;word>;标签
我必须编写一个程序来删除Python 删除所有<;word>;标签,python,regex,Python,Regex,我必须编写一个程序来删除和形式的所有表达式,其中单词是任意字母序列(小写和大写)和 删除单词与以前相同的形式和的所有表达式。例如,删除 到目前为止,我的代码如下所示: def remove_1( file_location ): """""" import re file_variable = open( file_location ) lines = file_variable.read() p = re.findall('<.*?>',
和
形式的所有表达式,其中单词是任意字母序列(小写和大写)和
删除单词与以前相同的形式
和
的所有表达式。例如,删除
到目前为止,我的代码如下所示:
def remove_1( file_location ):
""""""
import re
file_variable = open( file_location )
lines = file_variable.read()
p = re.findall('<.*?>', lines)
print p
substitution = re.compile('<.*?>')
print substitution.subn( ' ', p )
lines = file_variable.read()
print re.subn('<.*?>', ' ', line)
def remove_1(文件位置):
""""""
进口稀土
文件\变量=打开(文件\位置)
lines=文件\变量.read()
p=re.findall('',行)
打印p
替换=重新编译(“”)
打印替换.subn(“”,p)
我得到了一个指向
print.substitution.subn(“”,p)
的错误,其中指出我在运行程序时需要一个字符串或缓冲区。非常感谢您的帮助。行
包含您应该传递给subn
print substitution.subn( ' ', lines )
您正试图替换为字符串“p”。然而,p是findall的结果,findall是一个列表 我建议这样做:
def remove_1( file_location ):
""""""
import re
file_variable = open( file_location )
lines = file_variable.read()
p = re.findall('<.*?>', lines)
print p
substitution = re.compile('<.*?>')
print substitution.subn( ' ', p )
lines = file_variable.read()
print re.subn('<.*?>', ' ', line)
lines=file\u variable.read()
打印子目录(“”,,,行)