From bd0b957c9380f1ede0b53995985b06e35f423b20 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Mon, 08 Feb 2010 15:58:10 +0000 Subject: better handling of ords --- (limited to 'talogo.py') diff --git a/talogo.py b/talogo.py index 4d8efd5..601b561 100644 --- a/talogo.py +++ b/talogo.py @@ -68,7 +68,16 @@ class logoerror(Exception): Utility functions """ -def careful_divide(x,y): +def char_to_ord(x, y): + xx = x + yy = y + if type(x) == str or type(x) == unicode and len(x) == 1: + xx = ord(x[0]) + if type(y) == str or type(y) == unicode and len(y) == 1: + yy = ord(y[0]) + return xx, yy + +def careful_divide(x, y): try: if y==0: return 0 @@ -87,14 +96,7 @@ def taequal(x, y): typey = True if typex and typey: return x == y - if typex and len(x) == 1: - xx = ord(x[0]) - else: - xx = x - if typey and len(y) == 1: - yy = ord(y[0]) - else: - yy = y + xx, yy = char_to_ord(x, y) return xx==yy def taless(x, y): @@ -108,14 +110,7 @@ def taless(x, y): typey = True if typex and typey: return x < y - if typex and len(x) == 1: - xx = ord(x[0]) - else: - xx = x - if typey and len(y) == 1: - yy = ord(y[0]) - else: - yy = y + xx, yy = char_to_ord(x, y) return xx