import os v = r"D:\code\s21day14\20190409_192149.mp4" # r只要有出现转义符,自动在前面加一个\ print(os.path.dirname(v))