Re: 3 number and dot..
- From: "Chris Mellon" <arkanes@xxxxxxxxx>
- Date: Wed, 31 Oct 2007 15:50:25 -0500
On Oct 31, 2007 3:24 PM, Abandoned <besturk@xxxxxxxxx> wrote:
On Oct 31, 10:18 pm, Paul McNett <p...@xxxxxxxxxxxx> wrote:
Abandoned wrote:
Hi..
I want to do this:
for examle:
12332321 ==> 12.332.321
How can i do?
Assuming that the dots are always in the 3rd and 7th position in the string:
def conv(s, sep="."):
l = [s[0:3], s[3:6], s[6:]]
return sep.join(l)
print conv("12332321")
--
pkm ~http://paulmcnett.com
But it's starts from the end..
print conv("12332321")
123.323.21
This is wrong it would be 12.332.321
If you're doing this for thousands separators, look at the locale module:
doesn't do groupingimport locale
locale.setlocale(locale.LC_ALL, 'US') #the default C locale
'English_United States.1252'
'10,000'locale.format_string('%d', 10000, grouping=True)
'12,332,321'locale.format_string('%d', 12332321, grouping=True)
I only have the US locale available on this machine, but if you use a
locale that uses "." as the thousands separator, this should work for
you.
.
- References:
- 3 number and dot..
- From: Abandoned
- Re: 3 number and dot..
- From: Paul McNett
- Re: 3 number and dot..
- From: Abandoned
- 3 number and dot..
- Prev by Date: Re: Method needed for skipping lines
- Next by Date: Re: 3 number and dot..
- Previous by thread: Re: 3 number and dot..
- Next by thread: Re: 3 number and dot..
- Index(es):
Relevant Pages
|