python python snipet允许生成重复文件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python python snipet允许生成重复文件相关的知识,希望对你有一定的参考价值。

def generate_duplicate_name(f_name,output_path):
    ## snipet that allows duplicate file generation if need be
    # by: Cody Kochmann
    from os import listdir
    if f_name in listdir(output_path):
      if allow_duplicates == False:
        v_print(f_name+" already downloaded")
        return(False)
      else:
        placeholder_name=2
        while ((str(placeholder_name)+"."+f_name) in listdir(output_path)):
            placeholder_name+=1
        f_name=str(placeholder_name)+"."+f_name

以上是关于python python snipet允许生成重复文件的主要内容,如果未能解决你的问题,请参考以下文章