From 8065a23b679455dc88668ca1f0a71ccc7eba3fa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=B3pez=20Barr=C3=B3n?= Date: Sun, 8 Sep 2024 10:53:58 +1000 Subject: [PATCH] code snippet readability --- docs/source/index.rst | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/docs/source/index.rst b/docs/source/index.rst index d7c0e9d..3aff76f 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -16,18 +16,28 @@ .. py-editor:: :config: pyscript.toml + :env: index + # definition import naming class NameFileConvention(naming.Name, naming.File): config = dict(first=r'\w+', last=r'\w+', number=r'\d+') + # inspection name = NameFileConvention('john doe 07.jpg') - print(name.last) - print(name.number) + print(f"{name.last=}") + print(f"{name.number=}") + + # modification print(name.get(first='jane', number=99)) # returns new name string name.last = 'connor' # mutates current name print(name) - name.number = 'not_a_number' + + # validation + try: + name.number = 'not_a_number' + except ValueError as exc: + print(f"An error occurred: {exc}") .. toctree:: :maxdepth: 2