pathr icon indicating copy to clipboard operation
pathr copied to clipboard

should basename() follow Unix or Python?

Open gaborcsardi opened this issue 10 years ago • 4 comments

In that in Python basename("/foo/bar/") is "", and in Unix it is bar.

gaborcsardi avatar Apr 26 '16 07:04 gaborcsardi

R follows the Unix convention, btw.:

❯ basename("/foo/bar/")
[1] "bar"

gaborcsardi avatar Apr 26 '16 07:04 gaborcsardi

Essentially, Python always returns a file name (or an empty string). Which makes sense to me, but then I would not call it basename, just because that's a standard Unix name for something slightly different.

gaborcsardi avatar Apr 26 '16 07:04 gaborcsardi

I think following R + unix is probably the best route. It might be worth an as_python argument to allow that behaviour, so long as it's not the default...

richfitz avatar Apr 26 '16 08:04 richfitz

Yes, agreed.

As for the Python-like behaviour, how about having a separate function that behaves like that, i.e. always gives a file name (or nothing)?

gaborcsardi avatar Apr 26 '16 08:04 gaborcsardi