def reduceUnit(unitText): unit = UnitGroup(data) unit.update(unitText) unit.reduceGroup() return unit.unitString(unit.reducedList)
# This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import sys from unitdata import UnitData from unitgroup import UnitGroup data = UnitData() data.readData() fromText = "acres/s^2" fromUnit = UnitGroup(data) fromUnit.update(fromText) toText = "ft^2/ms^2" toUnit = UnitGroup(data) toUnit.update(toText) fromUnit.reduceGroup() toUnit.reduceGroup() if not fromUnit.categoryMatch(toUnit): print 'NO MATCH' else: num = float("45") #print u'%f IS %f' % (num, fromUnit.convert(num, toUnit)) print num, fromUnit.unitString(), '-->', fromUnit.convert(num, toUnit), toUnit.unitString()