Python Strip Unexpected Behavior
I was stripping a file name in python for routing purposes and I was getting some unexpected behavior with the python strip function. I've read the docs and searched online but hav
Solution 1:
strip()
would strip all the characters provided in the argument - in your case .
, m
and d
.
Instead, you can use os.path.splitext()
:
import os
os.path.splitext("Getting-StarteX.md")[0]
Solution 2:
If there is only one ".md" appearing at the end of the testing string, you can also use
"Getting-Started.md".split('.md')[0]
Thanks @Carpetsmoker remind me the assumption.
Post a Comment for "Python Strip Unexpected Behavior"