Article 5G394 python: convert old %-formatting style to "{}".format() style

python: convert old %-formatting style to "{}".format() style

by
kaz2100
from LinuxQuestions.org on (#5G394)
Can python experts please help me?

I am converting "%s" % style code to modern "{}".format() style.
Original code is:Code:sws = ["a", "an" ...]
... "|".join([r"%s\b" % w for w in sws])Red part needs to be rewritten. Simple replacement likeCode:"|".join([r"{}\b".format(w for w in sws)])does not work.

It looks like thatCode:"|".join([w + r"\b" for w in sws]) may work. But it is violating Python philosophy. It is UGRY! and COMPLEX compared to original beautiful code. Also, it is a violation of "there should be one- and preferably only one -obvious way to do it" rule.

To avoid unnecessary trouble in future, python way should be sought.

How to avoid these violations?

cheerslatest?d=yIl2AUoC8zA latest?i=C9pUnhucnEA:wdZ3R3SjB4Y:F7zBnMy latest?i=C9pUnhucnEA:wdZ3R3SjB4Y:V_sGLiP latest?d=qj6IDK7rITs latest?i=C9pUnhucnEA:wdZ3R3SjB4Y:gIN9vFwC9pUnhucnEA
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments