首页 > 解决方案 > 自动设置 str 列表和设置列表名称

问题描述

我的程序遇到问题,我希望程序使用两列从 txt 中识别字符串,然后将 txt 的字符串放在一个列表中,其中两列中的行名称,我不知道现在如何自动创建列表,但我仍然想制作一个程序,将他在 txt 中识别的所有内容都放在一个列表中。

link = "excelfilett.txt"
file = open(link, "r")
frames_path = []
is_count_frames_path = False
for line in file:
    if "[Routing Paths]" in line:
        is_count_frames_path = True
    if is_count_frames_path== True:
        for row in df_frame_array_load["[Name]"]:
            if row in line:
                a = line[0:4]
                a = list(a)
            if "[EthernetComNeed]" in line:
                break
        for row in df_frame_array_load["[Name2]"]:
            if row in line:
                a = line[0:4]
                a = list(a)
            if "[EthernetComNeed]" in line:
                break
    if "[EthernetComConfig]" in line:
        break
print(a)

但它只给了我这个:

['F','L','_','9']

虽然我想要类似的东西:

['FL_1','FL_1','FL_2','FL_9']

关于如何做到这一点的任何想法?

标签: python-3.xpandaslistdataframe

解决方案


推荐阅读