Formatting a numerical string w/commas
Wm. King
wjk at wjk.mv.com
Thu Feb 24 01:19:10 EST 2000
If this gets double posted, I apologize....
Having some difficulty with computer...
I am a newbie and thought this might be a possible solution
with some tightening up of course....
How about something like this ---
import re
pattern=re.compile("[0-9][0-9][0-9][0-9][\.\,$]")
test=123567789.98
teststr=str(test)
a = pattern.search(teststr)
while a:
b = a.regs[0]
c = b[0] + 1
teststr = teststr[0:c] + "," + teststr[c:]
a = pattern.search(teststr)
print teststr
Comments welcome
More information about the Python-list
mailing list