在python中找到所需参数下面的数字

时间:2017-05-23 16:28:02

标签: python

active

假如我要求 number_of_dimension declared_block_size actual_block_size declared_maximum_bl -------------------------------------------------------------------------------- 10 23100 5377 10924293219840 ,我应该actual_block_size。 请注意,我正在读取普通文本文件,而不是CSV文件。

1 个答案:

答案 0 :(得分:0)

您可以创建一个字典,将每个键指向其相应的值:

with open('your_file.txt', 'rb') as f:
    fields = f.readline().split(' ')  # get the titles from the first line
    values = f.readline().split(' ')  # get the values from the second line
dictionary = dict(zip(fields, keys))  # create a dictionary where each field points to its value
print dictionary['actual_block_size'] # you can access each value by its key (title)