This code will raise an XLRDError with the message 'not supported' and the description of the file format from the FILE_FORMAT_DESCRIPTIONS dictionary. The variable 'file_format' should be replaced with the desired file format.

Here is an example implementation:

from xlrd.biffh import XLRDError

FILE_FORMAT_DESCRIPTIONS = {
    'xlsx': 'Excel 2007 or later',
    'xls': 'Excel 97-2003',
    'csv': 'Comma Separated Values',
    # Add more file formats and descriptions as needed
}

file_format = 'xls'

try:
    raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format] + '; not supported')
except XLRDError as e:
    print(e)

Output:

Excel 97-2003; not supported
XLRDError: Handling Unsupported File Formats in Python

原文地址: https://www.cveoy.top/t/topic/mDBU 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录