Next / Previous / Contents / Shipman's homepage

7.12. indexer: moduleWrite()

This function writes a line to the isoents.py file defining a constant for one entity. Refer to Section 2, “Files for downloading” for the layout of these lines.

indexer
# - - -   m o d u l e W r i t e

def moduleWrite(outModule, uniEntity):
    '''Write the definition of one Python constant to the output module.

      [ (outModule is a writeable file) and
        (uniEntity is a unidata.UniEntity instance) ->
          outModule  +:=  a Python declaration for uniEntity ]
    '''

First we form the Python name by replacing periods in the entity name with underbars, then attaching the prefix (see Section 7.3.6, “PY_NAME_PREFIX).

indexer
    #-- 1
    uniChar = uniEntity.uniChar
    cp = uniChar.cp
    fullName = uniChar.fullName
    pyName = PY_NAME_PREFIX + uniEntity.id.replace(".", "_")

    #-- 2
    if cp > 0xFFFF:
        outFormat = "{0} = u'\U{1:08X}' # {2}\n"
    else:
        outFormat = "{0} = u'\u{1:04X}' # {2}\n"
    outModule.write(outFormat.format(pyName, cp, fullName))