面试题答案
一键面试import logging
def process_config_files(file_paths):
logging.basicConfig(
format='%(asctime)s - %(levelname)s - %(message)s',
level=logging.ERROR
)
for file_path in file_paths:
try:
with open(file_path, 'r') as file:
# 这里写处理文件的具体逻辑,比如读取文件内容等
content = file.read()
print(f"Processing file: {file_path}, content: {content}")
except FileNotFoundError:
logging.error(f"File {file_path} not found.")
你可以这样调用这个函数:
file_paths = ['path/to/file1.conf', 'path/to/nonexistent_file.conf', 'path/to/file2.conf']
process_config_files(file_paths)