# -*- coding: utf-8 -*- # 从网络地址中解析出系统文件路径 from urlparse import urlparse #py2版本, py3不一样 from os.path import basename, dirname, join url = "https://matplotlib.org/_downloads/font_file.py" parse_result = urlparse(url) print parse_result path = parse_result.path print path print join(basename(dirname(path)), basename(path)) """ ParseResult(scheme='https', netloc='matplotlib.org', path='/_downloads/font_file.py', params='', query='', fragment='') /_downloads/font_file.py _downloads/font_file.py """