def urljoin ( * urls ) : return reduce ( urlparse . urljoin , [ u . strip ( '/' ) + '/' for u in urls if u . strip ( '/' ) ] , '' ) . rstrip ( '/' )
python join url fragments without /
The default urlparse . urljoin behavior look strange Standard urlparse . urljoin ( http : // a . com / foo / bar ) Expect : http : // a . com / foo / bar Actually : http : // a . com / bar This function fix that .
def urljoin(*urls):
    """
    The default urlparse.urljoin behavior look strange
    Standard urlparse.urljoin('http://a.com/foo', '/bar')
    Expect: http://a.com/foo/bar
    Actually: http://a.com/bar

    This function fix that.
    """
    return reduce(urlparse.urljoin, [u.strip('/')+'/' for u in urls if u.strip('/')], '').rstrip('/')