On 02Jul2019 0707, brian.sk...@gmail.com 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 -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/3WW6WMTM42A7SCYGSKFUCCOMNFIU36VF/

Reply via email to