簡體   English   中英

打開並讀取:文件夾python中的多個xml文件

[英]Open and Read : Multiple xml files from the Folder python

我已經在一個文件夾中存儲了150多個XML文件。 我想從該文件夾中打開並讀取那些XML文件(大約150多個XML文件); 之后,我進行下一個分析。 我需要在以下代碼中進行哪些更改才能從該文件夾中打開/讀取多個XML文件?

from bs4 import BeautifulSoup
import lxml
import pandas as pd 

infile = open("F:\\itprocess\\xmltest.xml","r")
contents = infile.read()

os模塊的listdir()函數是讀取多個文件時使用的好方法。

from bs4 import BeautifulSoup
import lxml
import pandas as pd 
import os    

d = os.listdir()
for file in d:
    infile = open(file,"r")
    contents = infile.read()

當然,這里我假設您的當前目錄中只有XML文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM