Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 删除所有<;word>;标签_Python_Regex - Fatal编程技术网

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()
打印子目录(“”,,,行)