我正在编写一个python工具来处理一组文件.该工具将由其他用户而非我使用.
文件类似于以下格式:
#Text which I want to keep intact
#Lots of text
#Lots and lots of text
#Lots and lots and lots of other text
#Then in-between the file I have text in this format which I want to operate on:
ginstance
{
name ginstance_053D627B1349FA0BC57
node "FINDME"
inherit_xform on
visibility 255
blah
blah
blah
}
ginstance
{
name ginstance_053D627B1349FA0BC57
node "DONTFINDME"
inherit_xform on
visibility 255
blah
blah
blah
}
我想做的是:
>在输入文件中找到这些实例.
>检查实例中的特定单词.例如“ FINDME”
>如果以上单词存在,则从文件中删除实例.
即删除从“实例”开始到波浪形括号“}”的文本
我的工具将使用用户界面从用户那里获取此搜索字词(“ FINDME”).
我可以找到要删除的实例:
import re
with open("path to input file", &#