Skip to content

Commit c764fce

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

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

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

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

6868

69+
def isfile(path):
70+
try:
71+
return bool(os.stat(path)[0] & 0x8000)
72+
except OSError:
73+
return False
74+
75+
6976
def expanduser(s):
7077
if s == "~" or s.startswith("~/"):
7178
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)