[英]Ignore FileNotFoundError - I want to ignore when the ZIP not exist in the folder and jump to the next do the action
Ignore FileNotFoundError - I want to ignore when the ZIP not exist in the folder and jump to the next do the action.忽略 FileNotFoundError - 当文件夹中不存在 ZIP 时,我想忽略并跳转到下一步执行操作。 in case the other files exist, and I want it to do this test to ignore all files that do not exist in the folder and do only those that exist.
如果存在其他文件,我希望它执行此测试以忽略文件夹中不存在的所有文件,只执行存在的文件。
FileNotFoundError: [Errno 2] No such file or directory: 'CteProc.zip' FileNotFoundError: [Errno 2] 没有这样的文件或目录:'CteProc.zip'
from zipfile import ZipFile
import zipfile
import warnings
warnings.filterwarnings("ignore", category=FutureWarning)
exemploZip = zipfile.ZipFile('CteProc.zip')
exemploZip.extractall()
exemploZip = zipfile.ZipFile('CteProc (01).zip')
exemploZip.extractall()
exemploZip = zipfile.ZipFile('CteProc (02).zip')
exemploZip.extractall()
exemploZip = zipfile.ZipFile('CteProc (03).zip')
exemploZip.extractall()
use try and except block使用 try 和 except 块
import warnings
import zipfile
warnings.filterwarnings("ignore", category=FutureWarning)
try:
exemploZip = zipfile.ZipFile('CteProc.zip')
exemploZip.extractall()
except FileNotFoundError:
pass
try:
exemploZip = zipfile.ZipFile('CteProc (01).zip')
exemploZip.extractall()
except FileNotFoundError:
pass
try:
exemploZip = zipfile.ZipFile('CteProc (02).zip')
exemploZip.extractall()
except FileNotFoundError:
pass
try:
exemploZip = zipfile.ZipFile('CteProc (03).zip')
exemploZip.extractall()
except FileNotFoundError:
pass
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.