[Tutor] formatting and pretty printing nested structures

kevin parks kp8 at mac.com
Mon Feb 23 02:04:40 EST 2004


Hi. I have a list of lists. Inside the list are lists that are made up 
of strings and floats. When i print the list it prints the floats in 
the usual insane long wierdo format and i want to print them with 
string formatting so that they are more readable, so i somehow have to 
pick apart the nested items so that i can print:

0 ['C', 8.0, 8.0]
1 ['C#', 8.0099999999999998, 8.0833349227905273]

more like this:

0 ['C', 8.00, 8.000000]
1 ['C#', 8.01, 8.083333]

or even betterererer:

0    C    8.00    8.000000
1    C#   8.01    8.083333

What is the best way to format and print nested srtucres like i have 
here?

cheers,

kevin

-- -----

from rtcmix import *

c = ['C', 8.00, octpch(8.00)]
cs =['C#', 8.01, octpch(8.01)]
d = ['D', 8.02, octpch(8.02)]
ds = ['D#', 8.03, octpch(8.03)]
e = ['E', 8.04, octpch(8.04)]
f = ['F', 8.05, octpch(8.05)]
fs = ['F#', 8.06, octpch(8.06)]
g = ['G', 8.07, octpch(8.07)]
gs = ['G3', 8.08, octpch(8.08)]
a = ['A', 8.09, octpch(8.09)]
ash = ['A#', 8.10, octpch(8.10)]
b = ['B', 8.11, octpch(8.11)]

seq = [c, cs, d, ds, e, f, fs, g, gs, a, ash, b]

count = 0
print '\n','~~~' * 26
print seq

for i in seq:
	print count, i
	# print '%d \t %f' % (count, i)
	count = count + 1

print '~~~' * 26, '\n'




More information about the Tutor mailing list