从python中的文本文件中读取特定值

时间:2018-05-14 09:53:42

标签: python

以下是文本文件中的数据

# NOTE: These entries come from the source setup spreadsheet.# Do not alter them here.Instead, edit the $AI_META/source.gsk.xlsx file.#However, if this file has been copied into $AI_SERIAL, then editing it in place is expected.# In that case, you should remove this warning.
gsk.gs_attribute 1D 1Z 7C 0H 0T 0SH
gsk.gs_extract 1D 1Z 7C 1H 0T 0SH
gsk.gsportfolio 1D 1Z 7C 0H 0T 0SH

我想阅读gsk.gs_extract的7C。 提前致谢

1 个答案:

答案 0 :(得分:0)

试试这个: -

result = ''
for line in data('text.txt', 'r').readlines():
    words = line.split()
    if len(words)>3 and words[0] == 'gsk.gs_extract':
        result = words[3]
print result