import re #s 空格 +号表示至少出现一次 # path = 'C:\Users\czDesktoppy06\PY6_Day01\爬虫作业\2018_03_07\05_split.py' #前面加r表示元字符 path = r'C:UsersczDesktoppy06PY6_Day01爬虫作业2018_03_07 5_split.py' #用做分割 pattern = re.compile(r'\') s = pattern.split(path) print(s) filename = s[-1] print(filename)