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

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).

主站蜘蛛池模板: 洛南县| 赣榆县| 济宁市| 白沙| 永德县| 勐海县| 报价| 托克托县| 沁源县| 淮滨县| 仁怀市| 勃利县| 扶风县| 毕节市| 莱芜市| 西昌市| 惠州市| 周口市| 炉霍县| 晴隆县| 广丰县| 庐江县| 清远市| 且末县| 璧山县| 杭锦旗| 英山县| 南江县| 兴安盟| 余干县| 兴山县| 四川省| 兰西县| 肃北| 三穗县| 腾冲县| 邹城市| 浮山县| 宁夏| 二连浩特市| 云南省|