Python 字符分割时,只分割最后一个

split 换成rsplit(str,num),
str指分割字符串,
num指从后面开始分割出多少个

path = /home/username/data/text.txt 
 
path.split("/")
 
["home","username","data","text.txt "]
 
## 而使用rsplit:
 
path.rsplit("/",1)
 
["/home/username/data","text.txt "]

你可能感兴趣的:(Python 字符分割时,只分割最后一个)