Math.convertcore: remove unnecessary StringIO usage

Since the unit data is already a variable, we can read from it as is
This commit is contained in:
James Lu 2017-09-29 15:54:04 -07:00
parent 21a729d95a
commit 2460c0abca
1 changed files with 3 additions and 10 deletions

View File

@ -45,8 +45,8 @@ unitData = \
# followed by either equations or equivalency lists for the definition. # followed by either equations or equivalency lists for the definition.
# For equations, two are given, separated by a ';'. Both are functions of # For equations, two are given, separated by a ';'. Both are functions of
# "x", the first going from the unit to the equivalent unit and the second # "x", the first going from the unit to the equivalent unit and the second
# one in reverse. Any valid Python expression returning a float (including # one in reverse. Any valid Python expression returning a float (including
# the functions in the math module) should work. The equivalency list is a # the functions in the math module) should work. The equivalency list is a
# python list of tuples giving points for linear interpolation. # python list of tuples giving points for linear interpolation.
# #
# All units must reduce to primitive units, which are indicated by an '!' # All units must reduce to primitive units, which are indicated by an '!'
@ -1059,12 +1059,7 @@ class UnitData(dict):
"Read all unit data from file" "Read all unit data from file"
types = [] types = []
typeUnits = {} typeUnits = {}
try: lines = unitData.splitlines()
f = minisix.io.StringIO(unitData)
lines = f.readlines()
f.close()
except IOError:
raise UnitDataError('Can not read "units.dat" file')
for i in range(len(lines)): # join continuation lines for i in range(len(lines)): # join continuation lines
delta = 1 delta = 1
while lines[i].rstrip().endswith('\\'): while lines[i].rstrip().endswith('\\'):
@ -1229,5 +1224,3 @@ def units(type):
return '%s units: %s' % (type, ', '.join(unitsByType[type])) return '%s units: %s' % (type, ', '.join(unitsByType[type]))
else: else:
return 'valid types: ' + ', '.join(types) return 'valid types: ' + ', '.join(types)