python - For 循环中的 valor 错误,带有连接读取 xml 文件的路径
问题描述
我已经完成了一个 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_tag 功能:
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 个循环,但它只做一个我不知道为什么,因为在一个循环之后,勇气是:INCREMENTATION 2 INCREMENTATION STR 2
谢谢您的帮助 :)
解决方案
推荐阅读
- android - 您的应用未使用 AndroidX - Flutter 不允许我生成 apk
- xaml - 具有 Materialdesigninxaml 样式的按钮的中心边距定义
- python - 计算数据框中的日期列
- io - Ada.Text_IO.End_Of_File 缓冲副作用
- c# - 抄送电子邮件没有收到c#
- c++ - 为什么我的多线程并行求和函数的向量受限于线程数?
- python - 在 postgres 中将列数据类型从 VARCHAR 转换为 ARRAY(使用 Psycopg2)
- reference - 如何在 LibreOffice 中重新创建页面引用
- ibm-mq - 浏览 IBM MQ 获取消息
- c# - Azure Functions:如何在运行时读取 host.json 中的设置?