python 监测U盘插入和拔出
pip install psutil
import psutil def run(): while True: for item in psutil.disk_partitions(): if "removable" in item.opts: print("U盘插入") else: print("U盘拔出") if __name__ == "__main__": run()
pip install psutil
import psutil def run(): while True: for item in psutil.disk_partitions(): if "removable" in item.opts: print("U盘插入") else: print("U盘拔出") if __name__ == "__main__": run()