Exemple #1
0
def ReadVars(inFile):
    """ reads the variables and quantization bounds from a .qdat or .dat file

    **Arguments**

      - inFile: a file object

    **Returns**

      a 2-tuple containing:

        1) varNames: a list of the variable names

        2) qbounds: the list of quantization bounds for each variable

  """
    varNames = []
    qBounds = []
    fileutils.MoveToMatchingLine(inFile, 'Variable Table')
    inLine = inFile.readline()
    while inLine.find('# ----') == -1:
        splitLine = inLine[2:].split('[')
        varNames.append(splitLine[0].strip())
        qBounds.append(splitLine[1][:-2])
        inLine = inFile.readline()
    for i in xrange(len(qBounds)):

        if qBounds[i] != '':
            l = qBounds[i].split(',')
            qBounds[i] = []
            for item in l:
                qBounds[i].append(float(item))
        else:
            qBounds[i] = []
    return varNames, qBounds
Exemple #2
0
 def test_fileutils(self):
     filename = fileutils.__file__
     with open(filename) as inFile:
         line = fileutils.MoveToMatchingLine(inFile, 'pass')
         self.assertEqual(line, '  pass\n')
         self.assertRaises(fileutils.NoMatchFoundError,
                           fileutils.MoveToMatchingLine, inFile, 'pass')
     with open(filename) as inFile:
         self.assertRaises(fileutils.NoMatchFoundError,
                           fileutils.MoveToMatchingLine,
                           inFile,
                           'pass',
                           fullMatch=True)