Re: [Tutor] Even More Converter!

2008-03-22 Thread Kent Johnson
Alan Gauld wrote: > Bear in mind that the use of commas is very much a > local thing. In some parts of the world periods are used > and a comma indicates a decimal point so > > 123,456 > > could be 123 thousand 456 or 123 point 456 depending > on where the reader is from. > > If that is impo

Re: [Tutor] Even More Converter!

2008-03-22 Thread Rolando Pereira
Alan Gauld wrote: > > If that is important you might need to investigate a locale specific > way of defining the seperator. I know Windows has hooks to get > it from the local settings but I'm not sure about *nix and I don't > know if Python has a generic way. > > This might not matter to you

Re: [Tutor] Even More Converter!

2008-03-22 Thread Alan Gauld
<[EMAIL PROTECTED]> wrote > When Python gives me the answer to my conversion, > is there a way to create it so every 3 numbers a > comma is inserted? Bear in mind that the use of commas is very much a local thing. In some parts of the world periods are used and a comma indicates a decimal poi

Re: [Tutor] Even More Converter!

2008-03-22 Thread Kepala Pening
--- Original Message - From: bhaaluu <[EMAIL PROTECTED]> To: "Kepala Pening" <[EMAIL PROTECTED]> Cc: tutor@python.org Date: Sat, 22 Mar 2008 09:02:40 -0400 Subject: Re: [Tutor] Even More Converter! > import re > num = 12345678 > print ','.join(re.findall

Re: [Tutor] Even More Converter!

2008-03-22 Thread Dick Moores
How about: def intCommas(n):     """     inserts commas into integers. E.g. -12345678 -> -12,345,789     """     s = str(n)     sign = ''     if s[0] == '-':     sign = '-'     s = s[1:]     slen = len(s)     a = ''     for index in range(slen):     if index > 0 and index % 3 == slen

Re: [Tutor] Even More Converter!

2008-03-22 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > When Python gives me the answer to my conversion, is there a way to create it > so every 3 numbers a comma is inserted? Django uses this function: def intcomma(value): """ Converts an integer to a string containing commas every three digits. For example,

Re: [Tutor] Even More Converter!

2008-03-22 Thread Rolando Pereira
Kepala Pening wrote: > import re > > num = 123456789 > > print ','.join(re.findall("\d{3}", str(num))) > > output: > 123,456,789 > [snip] The problem with that is that it cuts the digits in the end of the number, if they can't form a 3 digit value. Example: import re n = 1234 print ",".join

Re: [Tutor] Even More Converter!

2008-03-22 Thread bhaaluu
ing <[EMAIL PROTECTED]> wrote: > > import re > > num = 123456789 > > print ','.join(re.findall("\d{3}", str(num))) > > output: > 123,456,789 > > > > > - Original Message ----- > From: [EMAIL PROTECTED] > To: tutor@python

Re: [Tutor] Even More Converter!

2008-03-22 Thread Kepala Pening
import re num = 123456789 print ','.join(re.findall("\d{3}", str(num))) output: 123,456,789 - Original Message - From: [EMAIL PROTECTED] To: tutor@python.org Date: Fri, 21 Mar 2008 21:49:18 -0700 Subject: [Tutor] Even More Converter! It works perfectly, so I am s

[Tutor] Even More Converter!

2008-03-21 Thread wackedd
After my last Email received I have been able to successfully create a Converter, currently it only has 6 units, but I will be adding more. My current code is # Converter Unit_Menu=""" 1) Centimeters 2) Inches 3) Feet 4) Yards 5) Miles 6) Millimeter Select a unit(1-6) """ >From = raw_input(Uni