Skip to content

Commit 28d2073

Browse files
committed
basename, dirname: Switch from os.path to pathlib
1 parent 29c1bc2 commit 28d2073

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/basename.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/python3
22

3-
import os
43
from optparse import OptionParser
4+
from pathlib import PurePath
55

66

7-
def basename(opts, names: list[str]):
8-
for name in names:
7+
def basename(opts, paths: list[PurePath]):
8+
for path in paths:
99
print(
10-
os.path.basename(name.removesuffix(opts.suffix)),
10+
path.name.removesuffix(opts.suffix),
1111
end="\0" if opts.zero else "\n",
1212
)
1313

@@ -52,4 +52,4 @@ def basename(opts, names: list[str]):
5252
else:
5353
opts.suffix = ""
5454

55-
basename(opts, args)
55+
basename(opts, map(PurePath, args))

src/dirname.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/python3
22

3-
import os
43
from optparse import OptionParser
4+
from pathlib import PurePath
55

66

7-
def dirname(opts, names: list[str]):
8-
for name in names:
9-
print(os.path.dirname(name) or ".", end="\0" if opts.zero else "\n")
7+
def dirname(opts, paths: list[PurePath]):
8+
for path in paths:
9+
print(path.parent, end="\0" if opts.zero else "\n")
1010

1111

1212
if __name__ == "__main__":
@@ -32,4 +32,4 @@ def dirname(opts, names: list[str]):
3232
if not args:
3333
parser.error("missing operand")
3434

35-
dirname(opts, args)
35+
dirname(opts, map(PurePath, args))

0 commit comments

Comments
 (0)