Python如何裁剪我想要的字符串?

Python如何裁剪我想要的字符串?,python,string,Python,String,文件中的字符串,如下所示: aux_source_directory(detail LIB_SRC) file(GLOB_RECURSE INC_ALL "./*.h") autogen_ui(LIB_SRC) add_library(qtdebugger_luadebugger ${LIB_SRC} ${INC_ALL}) target_link_libraries(qtdebugger_luadebugger PUBLIC Qt4::QtGui qtinfra debugger util i

文件中的字符串,如下所示:

aux_source_directory(detail LIB_SRC)
file(GLOB_RECURSE INC_ALL "./*.h")
autogen_ui(LIB_SRC)
add_library(qtdebugger_luadebugger ${LIB_SRC} ${INC_ALL})
target_link_libraries(qtdebugger_luadebugger PUBLIC Qt4::QtGui qtinfra debugger util infra opc)

if(test)
    add_subdirectory(unittest)
endif(test)

我想剪掉
target\u link\u libraries()
中的单词。我该怎么办呢?

我试过这种方法,似乎很有效:

#/usr/bin/python
#-*-编码:UTF-8-*-
进口稀土
file_object=open(“C:\Users/vlyu/Perforce/vlyu_GUI/qtgui/debugger/luadebugger/CmakeLists.txt”,“r”)
尝试:
fileText=file\u object.read()
if fileText.find(“目标链接库”)!=-1:
index1=fileText.index('target\u link\u libraries('))
index2=fileText.index('),index1)
打印索引1
打印索引2
t1=文件文本[index1:index2+1]
打印t1
最后:

文件\u object.close()
读取文件。绕线走。查找以
目标链接库开始的行
。提取
之间的字符串--你在哪一部分需要帮助?还有,你尝试过什么吗?请共享您的代码。如果它包含多行目标链接库函数该怎么办。还是读吧,每一行都不一定行。我认为最好将所有文件文本作为字符串读取。