Interesting discovery from automatic tools (python code)
José Matos
jaomatos at gmail.com
Sun Jul 31 16:57:35 UTC 2022
On Sun, 2022-07-31 at 07:15 +0100, José Matos wrote:
> In order to keep some sanity Python does not allow to stack
> prefixes, like
>
> fur"\begin_layout {layout}"
Actually thinking a bit and researching a little more this is wrong:
https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals
Looking in to the Python Language reference I see that it is possible
to use mix two:
stringprefix ::= "r" | "u" | "R" | "U" | "f" | "F"
| "fr" | "Fr" | "fR" | "FR" | "rf" | "rF" | "Rf" | "RF"
The issue that confused me is that since we need to keep the
compatibility with python2 we need to use the u prefix.
The u prefix was supported in Python 3 just version 3.3. Previously it
was available in python2:
"New in version 3.3: Support for the unicode legacy literal (u'value')
was reintroduced to simplify the maintenance of dual Python 2.x and 3.x
codebases. See PEP 414 for more information."
So actually the code above could simply be used as
fr"\begin_layout {layout}"
this only works for Python 3.6+, when the formatted strings were
introduced.
Apologies for this series of Python musings. :-D
--
José Abílio
More information about the lyx-devel
mailing list