from os import path
def openfile(filename):
dont_read_extensions = [".pdf", ".jpg"]
extension = path.splitext(filename)[1]
if extension in dont_read_extensions:
return #or you can raise custom exception
else:
with open(filename,"r") as f:
#do file operations
return # you can return with result
使其成为打开文件的函数
如果允许扩展,则检查扩展
阅读
否则返回或可能引发自定义异常
相关问题 更多 >
编程相关推荐