赞
踩
origin = 'http://download.tensorflow.org/models/imagenet/inception-2015-12-05.tgz' ###原链接
###split操作符
newname = origin.split('/')[-1] #以‘/ ’为分割f符,-1表示保留最后一段
###额外补充
newname_1 = origin.split('/')[-1] ###保留最后一段
newname_2 = origin.split('/')[:-1] ###取最后一段之前的所有
newname_3 = origin.split('/')[::-1] ###逆序输出
print(filename)
print(filename_1)
print(filename_2)
print(filename_3)
###输出
inception-2015-12-05.tgz
['http:', '', 'download.tensorflow.org', 'models', 'imagenet']
['inception-2015-12-05.tgz', 'imagenet', 'models', 'download.tensorflow.org', '', 'http:']
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。