Print precision?

Chris Liechti cliechti at gmx.net
Fri May 24 18:33:48 EDT 2002


Damian Menscher <menscher+python at uiuc.edu> wrote in 
news:awiH8.10159$U7.121015 at vixen.cso.uiuc.edu:

> I'm debugging my program that depends on the Numeric/LinearAlgebra
> packages.  In order to get an idea of what is going on, I just use
> lots of print statements.  But when you're printing a largish
> (32x32) matrix, the 8 decimal places given by default can take
> more space than they're worth.  Is there a simple way to cut this
> down to a more reasonable value (like zero)?
> 
> I guess I *could* write a function that prints each element
> separately....
> for i in range(32):
>      print "%.1f %.1f %.1f %.1f ..."%(m[i,0], m[i,1], m[i,2]....)
> But that just seems silly.

how about a function and map:

print ' '.join(map(lambda x: "%.1f" % x, m))
 
> On a related note, is there a way to change the default line width?
> Even if I expand my xterm to 200+ chars, Python wraps the matrix
> output at 80.

never heard of such a restriction. do you use a specific function or 
"print"? have you tried to resize first and then start python?

chris

-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list