我想读取文件夹中除名为“ xyz”的文件以外的所有文件。当我到达此文件时,我想跳过它并阅读下一个文件。
目前,我有以下代码:
for file in glob.glob('*.xml'):
data = open(file).read()
print(file)
Run Code Online (Sandbox Code Playgroud)
显然,这将读取该文件夹中的所有文件。我应该如何跳过文件“ xyz.xml”
该continue关键字是用于跳过的for循环的迭代有用:
for file in glob.glob('*.xml'):
if file=="xyz.xml":
continue
data = open(file).read()
print(file)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
850 次 |
| 最近记录: |