Next / Previous / Contents / Shipman's homepage

13.4. BaseSpeciesSet.__init__(): Constructor

The constructor sets up the internal data structures, opens the authority file, and reads its lines. The .readLine() method is virtual; only a concrete class knows the actual format of the authority file.

baseclasses.py
# - - -   B a s e S p e c i e s S e t . _ _ i n i t _ _   - - -

    def __init__(self, fileName):
        '''Constructor for BaseSpeciesSet.
        '''

        #-- 1 --
        self.spec4Map = {}
        self.spec6Map = {}
        self.engMap   = {}

We use the Scan object to work through the authority file. For more information on this object, see Section 4, “baseclasses.py: Prologue”. For the logic that processes each line, see Section 13.5, “BaseSpeciesSet.readLine().

baseclasses.py
        #-- 2 --
        # [ if fileName names a readable file ->
        #     scan  :=  a Scan object representing that file
        #   else -> raise IOError ]
        scan = Scan(fileName)

        #-- 3 --
        # [ scan is a Scan object ->
        #     if inFile contains only valid species lines ->
        #       self.spec4Map  +:=  entries mapping the uppercased
        #           4-letter codes from scan |-> Species objects
        #           representing those lines
        #       self.spec6Map  +:=  entries mapping the uppercased
        #           6-letter codes from scan |-> Species objects
        #           representing those lines
        #       self.engMap  +:=  entries mapping the English names
        #           from those lines |-> Species objects
        #           representing those lines
        #     else -> raise IOError ]
        while  not scan.atEndFile:
            #-- 3 body --
            # [ scan is a Scan object ->
            #     if the line in scan is not a valid species line ->
            #       raise IOError
            #     else ->
            #       self.spec4Map  +:=  an entry mapping the uppercased
            #           4-letter species code from that line |-> a
            #           Species object representing that line
            #       self.spec6Map  +:=  an entry mapping the uppercased
            #           6-letter species code from that line |-> a
            #           Species object representing that line
            #       self.engMap  +:=  an entry mapping the English name
            #           from that line |-> a Species object
            #           representing that line ]
            #       scan  :=  scan advanced to the next line, if any ]
            self.readLine(scan)
            scan.nextLine()

        #-- 4 --
        scan.close()