classLoggingEventHandler(FileSystemEventHandler):"""Logs all the events captured."""defon_moved(self, event):super(LoggingEventHandler, self).on_moved(event)
what ='directory'if event.is_directory else'file'
logging.info("Moved %s: from %s to %s", what, event.src_path,
event.dest_path)defon_created(self, event):super(LoggingEventHandler, self).on_created(event)
what ='directory'if event.is_directory else'file'
logging.info("Created %s: %s", what, event.src_path)defon_deleted(self, event):super(LoggingEventHandler, self).on_deleted(event)
what ='directory'if event.is_directory else'file'
logging.info("Deleted %s: %s", what, event.src_path)defon_modified(self, event):super(LoggingEventHandler, self).on_modified(event)
what ='directory'if event.is_directory else'file'
logging.info("Modified %s: %s", what, event.src_path)
我們可以按照同樣的邏輯撰寫自己的event_handler:
classMyEventHandler(FileSystemEventHandler):"""Logs all the events captured."""defon_created(self, event):super(LoggingEventHandler, self).on_created(event)
what ='directory'if event.is_directory else'file'
logging.warning("Created %s: %s by ", what, event.src_path)
CREATETABLE cats
(
id INT unsigned NOTNULLAUTO_INCREMENT,# Unique ID for the record
name VARCHAR(150)NOTNULL,# Name of the cat
owner VARCHAR(150)NOTNULL,# Owner of the cat
birth DATENOTNULL,# Birthday of the catPRIMARYKEY(id)# Make the id the primary key);