%s formatting in documentation (in stead of f-string)
Switching to lxml for xml parsing and generating, I was somewhat puzzeled by the usage line's like XHTML_NAMESPACE = "http://www.w3.org/1999/xhtml" XHTML = "{%s}" % XHTML_NAMESPACE With more modern f-string's this could also be written as XHTML = f"{{{XHTML_NAMESPACE}}}" This may be because I only started on Python on 3.7, and have never worked with any 2.x I quite understand there is no time to rework all the doc's in the low income on this project. Just two questions: - is there (another) good reason not to is f-string formatting? And if not - is there a way to assist on reworking the doc's Thomas Roes
Hi, t.roes@247interfaces.nl schrieb am 19.12.22 um 17:58:
Switching to lxml for xml parsing and generating, I was somewhat puzzeled by the usage line's like
XHTML_NAMESPACE = "http://www.w3.org/1999/xhtml" XHTML = "{%s}" % XHTML_NAMESPACE
With more modern f-string's this could also be written as
XHTML = f"{{{XHTML_NAMESPACE}}}"
This may be because I only started on Python on 3.7, and have never worked with any 2.x
I quite understand there is no time to rework all the doc's in the low income on this project. Just two questions:
- is there (another) good reason not to is f-string formatting? And if not - is there a way to assist on reworking the doc's
It's reasonable to update the docs to Py3 style by now, and a bit of that has already been done. The question is whether XHTML = f"{{{XHTML_NAMESPACE}}}" is really more readable than XHTML = "{%s}" % XHTML_NAMESPACE given the amount of curly braces with different meanings that a reader has to go through. To me, personally, the second seems quicker and more obvious to read, whereas it takes me a while to understand what the equivalent f-string does. I think this is a case where we should keep the (IMHO) simpler non-f-string variant. Stefan
participants (2)
-
Stefan Behnel
-
t.roes@247interfaces.nl