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()

 

相关文章: