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