如何提取网址中的文件名

u = urllib2.urlopen(addr)

data = u.read()


splitPath = addr.split('/')

fName = splitPath.pop()

print fName


就是这样,我也不会,不过后来看到list.pop()就搞定了


list.pop([i]) 

Remove the item at the given position in the list, and return it. If no index is specified, a.pop() removes and returns the last item in the list. (The square brackets around the i in the method signature denote that the parameter is optional, not that you should type square brackets at that position. You will see this notation frequently in the Python Library Reference.)


posted @ 2014-01-02 15:49  完美视界  阅读(401)  评论(0编辑  收藏  举报