For循环上的valor错误,该循环具有连接以读取xml fi的路径

2024-09-21 01:19:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我做了一个for循环,一个勇敢的人在我的循环结束时得到+1。 我的for循环是读取xml文件。它必须在读取文件上的标记CP时进行更新。我有4个不同标签的指令。但是我的for循环在第一个循环后停止工作。 对不起,我英语不好

增量是有效的。我用指纹检查过了

for cmd in root.iterfind('./instructs[@name="'+functions.str_instruct_number+'"]/command'):
    print('./instructs[@name="'+functions.str_instruct_number+'"]/command')
    print("cmd >",cmd.text)
    if cmd.text == "CP":
        try:
            for file in root.iterfind('./instructs[@name="'+functions.str_instruct_number+'"]/file'):
                print("file >", file.text)
                name_file = file.text
                tags_treatement_functions.CP_tag(name_file)
        except:
            print("for instruct morte")
        finally:
            print("finally CP pour voir")
            functions.instruct_number += 1
            functions.str_instruct_number = str(functions.instruct_number)
            print("INCREMENTATION", functions.instruct_number)
            print("INCREMENTATION STR", functions.str_instruct_number)
        tags_treatement_functions.RLD_tag(config.name_script)
    print(functions.instruct_number)
    print(functions.str_instruct_number)
    print(root.iterfind('./instructs[@name="'+functions.str_instruct_number+'"]/command'))
    print('./instructs[@name="'+functions.str_instruct_number+'"]/command')
    print("for finished")
print("for stopped")

这就是我的CP\u标签功能:

def CP_tag(name_file):
    bool_copy = True
    for update_file in glob.glob(config.video_path+"*.*"):
        if name_file == update_file:
            print("pas de téléchargement")
            bool_copy = False
            break
    if bool_copy == True:
        ftp = ftplib.FTP(config.FTP_adress, timeout=5)
        ftp.login(config.FTP_user, config.FTP_pwd)
        print("download ftp")
        try:
            ftp.retrbinary('RETR ' + name_file, open(config.local_temp_path+name_file, 'wb').write)
            print("download OK")
        except:
            print("download failed")
    bool_copy = True

我的循环可以完成4个循环,但它只能完成一个 我不知道为什么,因为在一个循环之后,勇气是: 增量2 递增STR 2

感谢您的帮助:)


Tags: textnamecmdconfignumberforfunctionscp

热门问题