python 判断doc还是docx格式
可以通过判断文件的扩展名来判断文件是否为doc还是docx格式。以下是一个示例代码:
filename = "example.docx"
extension = filename.split(".")[-1].lower()
if extension == "docx":
print("This is a docx file")
elif extension == "doc":
print("This is a doc file")
else:
print("This is neither a doc nor a docx file")
请注意,该方法只是根据文件名的扩展名进行判断,并不会检查文件的内容是否符合相应的格式要求。如果需要更精确的判断,可以使用一些第三方库,如python-docx库来解析文件内容。
原文地址: https://www.cveoy.top/t/topic/iNDC 著作权归作者所有。请勿转载和采集!