我有一个txt文件,我需要搜索一个特定的行,这是有效的,但在那行我需要去掉前14个字符,我感兴趣的列表元素部分是在运行时动态生成的.所以,场景是我运行了一个脚本,输出保存在output.txt中,现在我正在解析它,这是我试过的
load_profile = open('output.txt', "r"
read_it = load_profile.read()
myLines = [ ]
for line in read_it.splitlines():
if line.find("./testSuites/") > -1
myLines.append(line)
print myLines
Run Code Online (Sandbox Code Playgroud)
它给出了输出:
['*** Passed :) at ./testSuites/TS1/2013/06/17/15.58.12.744_14']
我只需要解析./testSuites/TS1/2013/06/17/15.58.12.744_14'部分和2013年,并且动态生成字符串的est.
能指导一下,实现它的最佳途径是什么?
在此先感谢Urmi
我想在字符串的末尾和开头添加'.我有
str1 = 'abc'
str2 = 'def'
strf = str1 + str2
print strf
Run Code Online (Sandbox Code Playgroud)
它给出了输出
abcdef
Run Code Online (Sandbox Code Playgroud)
我需要 'abcdef'
我试过加入
'''.join(strf)
Run Code Online (Sandbox Code Playgroud)
我试图在这里实现的是变量将被传递给解析一个xml,其中strf是xml的路径,所以它在开头和结尾都有.doc = ET.parse(strf)
PLease建议什么是最好的解决方案.提前致谢.URMI