一、实现创建文件夹和日志
#!/usr/bin/env python # -*- coding:utf-8 -*- # Author: nulige import os import datetime #获取系统时间 log_path_suffix = datetime.datetime.now().strftime('%Y-%m-%d ') #创建文件夹 folder_name = '\log' root_directory = 'D:\python\disk_monitor' try: os.mkdir(root_directory + folder_name) except OSError: pass #创建文件 file_path = r'D:\python\disk_monitor\log\event-ext-'+log_path_suffix+'.log' f = open(file_path, 'a')