Fieldset ยป entry

entry(name) โ†’ value or None
entry(name, loader) โ†’ value or None
entry(name, enforce_element: False, required: False, with_element: False) โ†’ object/value or None

Retrieve an entry's value from the fieldset, optionally supplying a loader to validate and/or transform the value, and/or an options object.

enoQ&A:
Meaning = 42
Green = Yes
Purpose =
python>>> document = enopy.parse(input)
>>> qa = document.fieldset('Q&A')

>>> qa.entry('Meaning')
'42'
>>> qa.entry('Purpose')
None
>>> qa.entry('Purpose', required=True)
ValidationError: ...
>>> qa.entry('Purpose', enforce_element=True)
None
>>> qa.entry('Beige', enforce_element=True)
ValidationError: ...
>>> qa.entry('Green', lambda name, value: value.upper())
'YES'

>>> def check_meaning(name, value):
...   if value == '42':
...     raise ValueError("That one's getting old!")
...   return value

>>> qa.entry('Meaning', check_meaning)
ValidationError: That one's getting old!

>>> qa.entry('Meaning', with_element=True)
[ <class Field name="Meaning" value="42"> , '42' ]

Parameters

name

The name of the entry as a string.

loader

A function returning the transformed/validated value or raising an error.The function is passed name and value, in that order, or just valueif your function only takes a single parameter.

options

enforce_element

Whether the entry must be present in the document (True or False, defaults to False)

enforce_value

Whether there must be a value or the entry is allowed to be empty (default to False)

required

Alias for enforce_value (this exists on many methods and depending on context refers to either element or value)

with_element

Whether to return a list with both the element and the value (defaults to False)

Return value

The entry's value, or None if empty.