Next / Previous / Contents / Shipman's homepage

36. class AgeCodeField: Age code

An object of this class represents the age code. For its values, see the specification.

We use the base class described in Section 27, “class SingleField: Generic single-character field”, which does most of the work. All we have to do is define the VALID_CODES and OLD_TRANSLATOR class attributes that describe the new and old age codes.

Note that VALID_CODES does not contain a space character, because the age code is required.
class AgeCodeField(SingleField):
    '''Represents an age code.

      Exports: as inherited.
    VALID_CODES = "012456789"
    OLD_TRANSLATOR = string.maketrans (

36.1. AgeCodeField.scanField()

Scans an age code field. Most of the work is done by Section 27.1, “SingleField.scanField(); we have only to supply our own class, and an extra argument to that method that describes the field in English for error messages.
# - - -   A g e C o d e F i e l d . s c a n F i e l d   - - -

    def scanField(encounter, scan, fieldName):
        '''Scan an age code field.
        SingleField.scanField(encounter, scan, fieldName,
                              AgeCodeField, "age code")