Next / Previous / Contents / NM Tech homepage

7.6. staticloader: addRegion()

Similar to Section 7.4, “staticloader: addNation.

staticloader
# - - -   a d d R e g i o n

def addRegion ( db, rawLine ):
    '''Add one row to the regions table.

      [ (db is a CBCData instance) and
        (rawLine is a valid regions file line) ->
          db.s  +:=  a new regions row made from rawLine ]

      Line format:
        0         1         2         3
        0123456789012345678901234567890
        CAN NT North West Territories
    '''
    #-- 1 --
    # [ reg_nation  :=  the nation code field from rawLine
    #   reg_code  :=  the region code field from rawLine
    #   reg_name  :=  the region name field from rawLine ]
    reg_nation = rawLine[:3]
    reg_code = rawLine[4:6]
    reg_name = unicode(rawLine[7:].strip())

    #-- 2 --
    # [ db.s  +:=  a new Region row added using region_code
    #              and region_name ]
    db.s.add ( db.Region ( reg_nation, reg_code, reg_name) )