Skip to content

Commit

Permalink
code snippet readability
Browse files Browse the repository at this point in the history
  • Loading branch information
chrizzFTD committed Sep 8, 2024
1 parent 66b4947 commit 8065a23
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8065a23

Please sign in to comment.