[Tutor] urljoin

Alan Gauld alan.gauld at yahoo.co.uk
Wed Jun 21 04:31:36 EDT 2017


On 20/06/17 16:25, Mats Wichmann wrote:

>> *""" so the resulting url: resultUrl should be *
>> http://data.parliament.uk/membersdataplatform/services/mnis/members/query/House=Commons/Constituencies
>>  *"""*

> But you don't really need urljoin for this... you can just format up the
> url string yourself, since you don't need any of the special behavior.

I'd tend to agree with Mats here. Since you just want to change
one substring the standard srtring formatting function
is probably easier to use here:

base =
r"http://data.parliament.uk/membersdataplatform/services/mnis/members/query/House={0}/Constituencies"

house = "Commons" # or house = "Lords"

url = base.format(house)


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list