std.path.buildPath

Russel Winder via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jun 12 01:33:52 PDT 2017


On Sun, 2017-06-11 at 13:21 +0000, Ryan Frame via Digitalmars-d-learn
wrote:
> On Sunday, 4 June 2017 at 18:15:36 UTC, Russel Winder wrote:
> > On Sun, 2017-06-04 at 17:56 +0200, Jacob Carlborg via 
> > Digitalmars-d- learn wrote:
> > > On 2017-06-04 07:44, Jesse Phillips wrote:
> > > 
> > > > What is your expected behavior? Throw an exception? You can't
> > > > really
> > > > append an absolute path to another.
> > > 
> > > Of course you can. I expect buildPath("/foo", "/bar") to 
> > > result in "/foo/bar". That's how Ruby behaves.
> > 
> > And Python, Groovy, Java, Kotlin, Ceylon, C++, …
> 
> Python 3.5.1 on my machine:
> 
>      >>> os.path.join("/asdf", "/bcd")
>      '/bcd'
>      >>> os.path.join("asdf", "/bcd")
>      '/bcd'

####### #### you are absolutely right, and it is clearly stated in the
documentation that this is the expected behaviour. Clearly, I have
never tried doing that in 20 years of playing with Python. And it has
never come up in 12 years of running Python workshops!

This behaviour is reinforced by pathlib which is the modern way of
doing paths in Python, replacing os.path:

    import pathlib

    p = pathlib.Path()
    p = p.joinpath('/', 'usr', '/local', '/bin')
    print(p)

result /bin.

So given Python is one of the targets for D, consistency of behaviour
implies D is currently doing the right thing.
 
-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder at ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel at winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20170612/53f2e79a/attachment.sig>


More information about the Digitalmars-d-learn mailing list