DarkBlue wrote:
On Aug 5, 7:06 pm, Chris Withers wrote:
Peter Otten wrote:
locale.setlocale(locale.LC_ALL, ("en_US", "UTF-8"))
'en_US.UTF8'
print locale.currency(13535, grouping=True)
$13,535.00
Okay, so if I'm writing a wsgi app, and I want to format depending on
the choices of the curren
On Aug 5, 12:33 pm, John Nagle wrote:
> There's got to be a better way to do this:
>
> def editmoney(n) :
> return((",".join(reduce(lambda lst, item : (lst + [item]) if
> item else lst,
> re.split(r'(\d\d\d)',str(n)[::-1]),[])))[::-1])
>
> >>> editmoney(0)
> '0'
> >>> edit
Steven D'Aprano wrote:
> On Thu, 05 Aug 2010 00:22:57 -0700, geremy condra wrote:
>
>> locale.setlocale(locale.LC_ALL, "")
>>> 'de_DE.UTF-8'
>> print locale.currency(13535, grouping=True)
>>> 13.535,00 €
>> print locale.format("%d", 13535, grouping=True)
>>> 13.535
>>>
>>> Peter
>>
>
On 8/5/2010 12:36 PM, MRAB wrote:
You don't need to reverse the string:
def thous_format(integer_string):
"""
add comma thousands separator(s) to an integer-valued string
"""
return re.sub(r"(?<=\d)(?=(?:\d\d\d)+$)", ",", integer_string)
Nice! My first encounter with a look-behind
John Posner wrote:
On 8/5/2010 12:33 AM, John Nagle wrote:
There's got to be a better way to do this:
def editmoney(n) :
return((",".join(reduce(lambda lst, item : (lst + [item]) if
item else lst,
re.split(r'(\d\d\d)',str(n)[::-1]),[])))[::-1])
Here's a more elegant variant, using regexp lo
On 8/5/2010 12:33 AM, John Nagle wrote:
There's got to be a better way to do this:
def editmoney(n) :
return((",".join(reduce(lambda lst, item : (lst + [item]) if
item else lst,
re.split(r'(\d\d\d)',str(n)[::-1]),[])))[::-1])
Here's a more elegant variant, using regexp lookahead:
def thous_
Chris Withers wrote:
> Peter Otten wrote:
> locale.setlocale(locale.LC_ALL, ("en_US", "UTF-8"))
>> 'en_US.UTF8'
> print locale.currency(13535, grouping=True)
>> $13,535.00
>
> Okay, so if I'm writing a wsgi app, and I want to format depending on
> the choices of the currently logged in us
On Aug 5, 7:06 pm, Chris Withers wrote:
> Peter Otten wrote:
> locale.setlocale(locale.LC_ALL, ("en_US", "UTF-8"))
> > 'en_US.UTF8'
> print locale.currency(13535, grouping=True)
> > $13,535.00
>
> Okay, so if I'm writing a wsgi app, and I want to format depending on
> the choices of the
Peter Otten wrote:
locale.setlocale(locale.LC_ALL, ("en_US", "UTF-8"))
'en_US.UTF8'
print locale.currency(13535, grouping=True)
$13,535.00
Okay, so if I'm writing a wsgi app, and I want to format depending on
the choices of the currently logged in users, what would you recommend?
I can't
On Thu, 05 Aug 2010 00:22:57 -0700, geremy condra wrote:
> locale.setlocale(locale.LC_ALL, "")
>> 'de_DE.UTF-8'
> print locale.currency(13535, grouping=True)
>> 13.535,00 €
> print locale.format("%d", 13535, grouping=True)
>> 13.535
>>
>> Peter
>
> I had literally no idea this existed
On Wed, Aug 4, 2010 at 11:30 PM, Peter Otten <__pete...@web.de> wrote:
> John Nagle wrote:
>
>> There's got to be a better way to do this:
>>
>>
>> def editmoney(n) :
>> return((",".join(reduce(lambda lst, item : (lst + [item]) if
>> item else lst,
>> re.split(r'(\d\d\d)',str
John Nagle wrote:
> There's got to be a better way to do this:
>
>
> def editmoney(n) :
> return((",".join(reduce(lambda lst, item : (lst + [item]) if
> item else lst,
> re.split(r'(\d\d\d)',str(n)[::-1]),[])))[::-1])
>
>
> >>> editmoney(0)
> '0'
> >>> editmoney(13535)
On Wed, 04 Aug 2010 21:33:31 -0700, John Nagle wrote:
> There's got to be a better way to do this:
>
>
> def editmoney(n) :
> return((",".join(reduce(lambda lst, item : (lst + [item]) if
> item else lst,
> re.split(r'(\d\d\d)',str(n)[::-1]),[])))[::-1])
What does the name
John Nagle writes:
> def editmoney(n) :
> return((",".join(reduce(lambda lst, item : (lst + [item]) if
> item else lst,
> re.split(r'(\d\d\d)',str(n)[::-1]),[])))[::-1])
Too obscure. I usually use something like this:
def editmoney(n):
if n < 0: return '-' + edit
There's got to be a better way to do this:
def editmoney(n) :
return((",".join(reduce(lambda lst, item : (lst + [item]) if
item else lst,
re.split(r'(\d\d\d)',str(n)[::-1]),[])))[::-1])
>>> editmoney(0)
'0'
>>> editmoney(13535)
'13,535'
>>> editmoney(-14535)
'-14,535'
>>> e
15 matches
Mail list logo