我用replace()编写了一个小函数来清理重定向文件,去掉了逻辑,基本上是纯英语的。你知道吗
到目前为止我有:
def redir_cleanup(searchFor, replaceWith):
inputFile = open('input', 'r')
outputFile = open('output', 'w+')
for line in inputFile:
print "Replacing %s with '%s'" % (searchFor, replaceWith)
outputFile.write(line.replace(searchFor, replaceWith))
redir_cleanup("RedirectMatch permanent ", "")
redir_cleanup("RewriteRule ^", "")
redir_cleanup(" [L,R=301]", "")
redir_cleanup("RewriteCond %{QUERY_STRING} ^search\=(", "")
redir_cleanup(")$ [NC]", "")
redir_cleanup("\+", " ")
redir_cleanup("[NC,OR]", "")
redir_cleanup("RewriteRule ^.* ", "")
但它只会删除最上面的呼叫,我需要循环吗?你知道吗
函数从一个名称的文件中读取,然后写入另一个名称的文件。但是名字从不改变,所以它一直使用相同的输入。尝试在函数外部打开文件并将其传入。你知道吗
相关问题 更多 >
编程相关推荐