projects
/
gonvert
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
ac3cdbc
)
Removing dependence on string module
author
Ed Page
<eopage@byu.net>
Thu, 29 Oct 2009 12:54:18 +0000
(07:54 -0500)
committer
Ed Page
<eopage@byu.net>
Thu, 29 Oct 2009 12:54:18 +0000
(07:54 -0500)
src/converters.py
patch
|
blob
|
history
diff --git
a/src/converters.py
b/src/converters.py
index
f760419
..
d4f9bc2
100644
(file)
--- a/
src/converters.py
+++ b/
src/converters.py
@@
-5,9
+5,6
@@
the return value is the converted value to or from base
"""
"""
-import evil_globals
-
-
# used for Computer numbers base definitions.
ALPHA_NUMERIC = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
# used for Computer numbers base definitions.
ALPHA_NUMERIC = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
@@
-230,7
+227,7
@@
class base_converter(object):
position = len(value) #length of the string that is to be converted
for x in value:
position = position-1
position = len(value) #length of the string that is to be converted
for x in value:
position = position-1
- result = long(result + long(long(string.find(ALPHA_NUMERIC,x))*(long(base)**long(position))))
+ result = long(result + long(long(ALPHA_NUMERIC.find(x))*(long(base)**long(position))))
return result
def from_base(self,value,base):
return result
def from_base(self,value,base):
@@
-265,11
+262,11
@@
class function(object):
#value is assumed to be a string
#convert from a defined function to base
def to_base(self,value,(to_base,from_base)):
#value is assumed to be a string
#convert from a defined function to base
def to_base(self,value,(to_base,from_base)):
- exec "y="+to_base[:string.find(to_base,'x')]+str(value)+to_base[string.find(to_base,'x')+1:]
+ exec "y="+to_base[:to_base.find('x')]+str(value)+to_base[to_base.find('x')+1:]
return y
def from_base(self,value,(to_base,from_base)):
return y
def from_base(self,value,(to_base,from_base)):
- exec "y="+from_base[:string.find(from_base,'x')]+str(value)+from_base[string.find(from_base,'x')+1:]
+ exec "y="+from_base[:from_base.find('x')]+str(value)+from_base[from_base.find('x')+1:]
return y
return y