官术网_书友最值得收藏!

How it works

In the constructor for URLUtility, there is a call to urlib.parse.urlparse.  The following demonstrates using the function interactively:

>>> parsed = urlparse(const.ApodEclipseImage())
>>> parsed
ParseResult(scheme='https', netloc='apod.nasa.gov', path='/apod/image/1709/BT5643s.jpg', params='', query='', fragment='')

The ParseResult object contains the various components of the URL.  The path element contains the path and the filename.  The call to the .filename_without_ext property returns just the filename without the extension:

@property
def filename_without_ext(self):
filename = os.path.splitext(os.path.basename(self._parsed.path))[0]
return filename

The call to os.path.basename returns only the filename portion of the path (including the extension). os.path.splittext() then separates the filename and the extension, and the function returns the first element of that tuple/list (the filename).

主站蜘蛛池模板: 长顺县| 慈溪市| 齐河县| 广汉市| 盐池县| 北流市| 扶绥县| 牙克石市| 北票市| 阳高县| 西宁市| 台山市| 土默特右旗| 建德市| 阳曲县| 和平县| 手游| 兴安县| 正定县| 林州市| 博湖县| 页游| 西乌| 拜泉县| 新田县| 绥江县| 饶河县| 莱州市| 普洱| 光泽县| 大方县| 乐业县| 正阳县| 自贡市| 三原县| 定边县| 平安县| 农安县| 丰镇市| 巴彦县| 芷江|