Re: Can Python format long integer 123456789 to 12,3456,789 ?

2006-06-01 Thread james . wondrasek

A.M wrote:
> Hi,
>
> Is there any built in feature in Python that can format long integer
> 123456789 to 12,3456,789 ?
>
> Thank you,
> Alan

I did this for putting commas into monetary amounts (thus the .2f):

def commas(value):
return "".join(commafy("%.2f" % value))

def commafy(s):
pieces = s.split(".")
l = len(pieces[0])
for i in range(0,l):
if (l - i) % 3 or not i:
yield pieces[0][i]
else:
yield ","
yield pieces[0][i]
if len(pieces) > 1:
yield "." + pieces[1]


jtm

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to debug python code?

2006-04-03 Thread james . wondrasek
I don't have an example, but what I do is insert:

import pdb
pdb.set_trace()

before the code that I think is causing the problem
(or that the traceback barfed at).

Then hit 'l' (lowercase L) to get a list of the code
which is being executed.

Use 'p' to look at variables. eg p some_local

Use 'n' to execute the current line of code
(doesn't follow method or function calls)

Use 's' to step through code, including following
function and method calls.

Finally, 'c' to continue execution as normal.

There are other options, but that should get you started.
And look at the article linked elsewhere in this thread.

pdb - because fencing off Alaska is too damn slow, binary
search or not.

jtm

-- 
http://mail.python.org/mailman/listinfo/python-list