首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >文件多次追加到我的列表中。

文件多次追加到我的列表中。
EN

Stack Overflow用户
提问于 2020-06-23 20:23:13
回答 1查看 128关注 0票数 0

在我下面的函数中,run_check是一个全局列表。当我在下面追加文件时,文件被追加的次数与处理列表中的文件一样多。

如果第三个循环中的run_check语句不是真的,那么是否有一种方法只将文件追加到if

代码语言:javascript
复制
def lookForProcessingFiles(ctf,gcc):
    processingList = []

    for file in os.listdir(Incoming_Data):
        if (file[:32] == ctf[:32]) and (file[:32] == gcc[:32]):
            processingList.append(file)

    for x,y in itertools.combinations(processingList,2):
        if (x[:58] == y[:58]) and x.endswith('.raw') and y.endswith('.csv'):
            #checkDict()
            #move y then move x to input folder       
            print(x,y)

    for file in processingList:
        if (file[:32] == ctf[:32]) and (file[:32] == gcc[:32]) and  file.endswith('last.txt'):
            #checkDict()
            #move file to input
            #remove files from runs_dict
            print('Last: ' + file)

        else:
            #runs_dict.update({'CTF: ' + ctf[8:27]:ctf, 'GCC: ' +gcc[8:27]:gcc})
            run_check.append(ctf)
            run_check.append(gcc)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-23 20:28:50

使用any()测试所有文件。

代码语言:javascript
复制
if not any(file[:32] == ctf[:32]) and (file[:32] == gcc[:32]) and  file.endswith('last.txt') for file in processingList):
    run_check.append(ctf)
    run_check.append(gcc)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62543149

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档