diff --git a/index.md b/index.md index 757d86c..977e48b 100644 --- a/index.md +++ b/index.md @@ -332,6 +332,7 @@ This file gets generated by [this script](index.py). - [Pathlib home and cwd](notes/20220904163710.md) - [Pathlib list files in directory](notes/20220904164101.md) - [Read / write files the modern way](notes/20221202131250.md) +- [Split file name and extension](notes/20240711112258.md) ## Pdf diff --git a/notes/20240711112258.md b/notes/20240711112258.md new file mode 100644 index 0000000..deadbb1 --- /dev/null +++ b/notes/20240711112258.md @@ -0,0 +1,14 @@ +# split file name and extension + +`pathlib` has you covered, just make a `Path` object and access the `stem` and `suffix` attributes: + +``` +import pathlib + +path = pathlib.Path('20240711112258.md') + +print(path.stem) # 20240711112258 +print(path.suffix) # .md +``` + +#pathlib