modernize some Python code

Since we now require Python 3.6, we can use f-strings instead of
format() to make the code more readable.

* doc/org/tut01.org, doc/org/tut02.org, doc/org/tut03.org,
doc/org/tut21.org, doc/org/tut24.org, doc/org/tut90.org,
python/spot/__init__.py, python/spot/jupyter.py, tests/python/acc.py,
tests/python/acc_cond.ipynb, tests/python/complement_semidet.py,
tests/python/decompose.ipynb, tests/python/formulas.ipynb,
tests/python/highlighting.ipynb, tests/python/ipnbdoctest.py,
tests/python/ltlf.py, tests/python/parity.ipynb,
tests/python/product.ipynb, tests/python/relabel.py,
tests/python/satmin.ipynb, tests/python/stutter-inv.ipynb,
tests/python/twagraph-internals.ipynb, tests/python/zlktree.ipynb: Use
f-strings.
This commit is contained in:
Alexandre Duret-Lutz 2024-03-26 20:35:10 +01:00
parent df44f7a5c2
commit 7ac570fa3f
23 changed files with 292 additions and 327 deletions

View file

@ -779,8 +779,7 @@
],
"source": [
"def show_prod(a1, a2, res):\n",
" s1 = a1.num_sets()\n",
" display_inline(a1, a2.show('.tvb+{}'.format(s1)), res)\n",
" display_inline(a1, a2.show(f'.tvb+{a1.num_sets()}'), res)\n",
"\n",
"show_prod(a1, a2, prod)"
]
@ -1714,7 +1713,7 @@
"\n",
"The one-liner above is wrong for two reasons:\n",
"\n",
" - if `left` and `right` are non-deterministic, their product could be deterministic, so calling prop_universal(False) would be wrong. \n",
" - if `left` and `right` are non-deterministic, their product could be deterministic, so calling `prop_universal(False)` would be wrong. \n",
"\n",
" - the use of the `and` operator on `trival` is misleading in non-Boolean context. The `&` operator would be the correct operator to use if you want to work in threed-valued logic. Compare: "
]
@ -1746,8 +1745,7 @@
"maybe = spot.trival_maybe()\n",
"for u in (no, maybe, yes):\n",
" for v in (no, maybe, yes):\n",
" print(\"{u!s:>5} & {v!s:<5} = {r1!s:<5} {u!s:>5} and {v!s:<5} = {r2!s:<5}\"\n",
" .format(u=u, v=v, r1=(u&v), r2=(u and v)))"
" print(f\"{u!s:>5} & {v!s:<5} = {u&v!s:<5} {u!s:>5} and {v!s:<5} = {u and v !s:<5}\")"
]
},
{
@ -2444,7 +2442,7 @@
"display(p3.show('.1'))\n",
"pairs = p3.get_product_states()\n",
"for s in range(p3.num_states()):\n",
" print(\"{}: {}\".format(s, pairs[s]))"
" print(f\"{s}: {pairs[s]}\")"
]
},
{
@ -2465,7 +2463,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"87.6 µs ± 982 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)\n"
"107 µs ± 2.91 µs per loop (mean ± std. dev. of 7 runs, 10,000 loops each)\n"
]
}
],
@ -2482,7 +2480,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"2.14 µs ± 9.61 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)\n"
"2.23 µs ± 47.3 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)\n"
]
}
],
@ -2525,7 +2523,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
"version": "3.11.8"
}
},
"nbformat": 4,