On Tue, 2026-03-10 at 15:58 +0000, Juergen Spitzmueller wrote:
> + m = regexp.match(document.body[k])
> + if m:
> + pretext = m.group(1)
> + cmd = m.group(2)
> + arg = m.group(3)
> + posttext = m.group(4)
In the above code you can:
* use the walrus operator := to simplify the code by doing the assignment in the
if statement;
* use the fact that group can accept a tuple instead of a single argument.
```
if m := regexp.match(document.body[k]):
pretext, cmd, arg, posttext = m.group(1, 2, 3, 4)
```
I like this version because it is shorter and IMHO it is easier to read. On the
other hand this is a matter of taste and the above code is correct.
https://docs.python.org/3/whatsnew/3.8.html#assignment-expressions
https://docs.python.org/3/library/re.html#re.Match.group
Best regards,
PS: I need to use a real emoticon or else Scott's script will consider the
walrus as emoticon, thus this reference makes the false positive a true positive
:-D
--
José Abílio
--
lyx-devel mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-devel