[Tutor] Even More Converter!

Kepala Pening kepalapening at gmail.com
Sat Mar 22 11:17:25 CET 2008

import re

num = 123456789

print ','.join(re.findall("\d{3}", str(num)))


----- Original Message -----
From: wackedd at mac.com
To: tutor at python.org
Date: Fri, 21 Mar 2008 21:49:18 -0700
Subject: [Tutor] Even More Converter!

It works perfectly, so I am sure my question will not be hard to answer.
When Python gives me the answer to my conversion, is there a way to create it 
so every 3 numbers a comma is inserted?
Such as: 1 mile is 5,280 feet. Instead of 1 mile is 5280 feet. Yes a simple 
thing, but something which I believe will make it look better.
Also is there a way to make this so I don't have to go through every 
individual line of code and add *insert comma* or something to it, simply 
at the top like how the Unit Menu is placed only once there, and yet 
applies to the whole document. Thank you

More information about the Tutor mailing list