【发布时间】:2020-07-21 11:30:28
【问题描述】:
我正在尝试从文本文件中提取某些数据字符串。 我使用的代码如下。我想从该文本文件中读取特定的字符串(所有操作),然后将其存储在数组或列表中(如果找到)。然后以相同的顺序显示。
import string
solution_path = "/homer/my_dir/solution_detail.txt"
solution = open(solution_path).read()
all_actions = ['company_name','email_address','full_name']
n = 0
sequence_array = []
for line in solution:
for action in all_actions:
if action in line:
sequence_array[n] = action
n = n+1
for x in range(len(sequence_array)):
print (sequence_array[x])
但是这段代码没有做任何事情,只是运行没有任何错误。
【问题讨论】:
标签: python arrays oop text-files text-extraction