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

 

posted @ 2020-05-11 13:47  唐小沫  阅读(2185)  评论(1编辑  收藏  举报