Skip to content

Commit 8a2a033

Browse files
committed
os.path: implement isfile()
Signed-off-by: Michael Hirsch <[email protected]>
1 parent e6b89ea commit 8a2a033

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

python-stdlib/os-path/os/path.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ def isdir(path):
6666
return False
6767

6868

69+
def isfile(path):
70+
try:
71+
mode = os.stat(path)[0]
72+
return mode & 0x8000
73+
except OSError:
74+
return False
75+
76+
6977
def expanduser(s):
7078
if s == "~" or s.startswith("~/"):
7179
h = os.getenv("HOME")

python-stdlib/os-path/test_path.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@
2020
assert isdir(dir + "/os")
2121
assert not isdir(dir + "/os--")
2222
assert not isdir(dir + "/test_path.py")
23+
24+
assert not isfile(dir + "/os")
25+
assert isfile(dir + "/test_path.py")
26+
assert not isfile(dir + "/test_path.py--")

0 commit comments

Comments
 (0)