On 02Jul2019 0707, [email protected] wrote:
Taking swapping a file extension as an example of a particular transformation of interest, it would
be achieved with something like s.replace(".htm", ".html", only_end=True).
Please don't use string functions for file system paths, they are not
reliable cross-platform.
Use pathlib or (if you need pre-3.4 compatibility) os.path:
>>> p = Path(...)
>>> p = p.with_suffix(".html") if p.match("*.htm") else p
>>> p = "..."
>>> p0, p1 = os.path.splitext(p)
>>> p = (p0 + ".html") if os.path.normcase(p1) ==
os.path.normcase(".htm") else p
Cheers,
Steve
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/3WW6WMTM42A7SCYGSKFUCCOMNFIU36VF/