Python:读取可更改的XML文件

2024-05-03 17:54:04 发布

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

假设我有这个代码:

import xml.etree.ElementTree as ET
from time import sleep

def get_src():
    while True:
        path = "input.xml"
        root = ET.parse(path).getroot()
        nodes = root.findall('body/video')
        for node in nodes:
            src = node.get('src')

            yield src

for i in get_src():
    print(i)
    sleep(3)

当xml文件的内容正在更改并且循环已经在运行时,如何让python刷新nodes


Tags: path代码inimportsrcnodeforget