Last active
December 10, 2022 16:13
-
-
Save simryang/f9f2f94319fa9f2e43122a7d78613aa5 to your computer and use it in GitHub Desktop.
split ext filename from full path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from pathlib import Path | |
p = "/home/pi/src/projA/kk.c" | |
pp = os.path.splitext(p) | |
# pp = ('/home/pi/src/projA/kk', 'c') | |
print(f"filename with path={pp[0]}, extension={pp[1]}") | |
p1 = Path(p) | |
p1ext = p1.suffix | |
p1name = p1.name | |
print(f"filename={p1}, ext={p1ext}, name={p1name}") | |
# filename=/home/pi/src/projA/kk.c, ext=.c, name=kk.c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment