array{uint32}

Erik Johnson nobody at invalid.com
Wed Apr 18 12:35:40 EDT 2007


"Daniel Nogradi" <nogradi at gmail.com> wrote in message
news:mailman.6660.1176906192.32031.python-list at python.org...
> > I have a function that returns a array{uint32}, is there any way to
output
> > that to screen in a more user friendly format? At the moment when I
print it
> > by itself it appears as [65541L], which isn't much used to anyone.
>
> I'm not sure I understand your question precisely but this might help:
>
> >>> mylist = [65541L]
> >>> mylist
> [65541L]
> >>> mylist[0]
> 65541L
> >>> int(mylist[0])
> 65541
> >>>

Right, so getting rid of the 'L' is one improvement.  You might also check
out the pprint module:

>>> l = range(30)
>>> l
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 2
2, 23, 24, 25, 26, 27, 28, 29]
>>> from pprint import pprint
>>> pprint(l)
[0,
 1,
 2,
 3,
<snip>
 28,
 29]
>>>

    You can use C-like print formatting statements:

>>> l = [-3, 0, 101320, 67]
>>> pprint(l)
[-3, 0, 101320, 67]
>>> for i in l:
...   print i
...
-3
0
101320
67
>>> for i in l:
...   print '%6i' % i
...
    -3
     0
101320
    67
>>>
# the above probably doesn't disply correctly unless you are viewing with a
monospaced font)

    You could sort the list, then split it up into N separate lists so that
you can format multiple columns of sorted integers...

You haven't given any real information about your idea of a "user friendly
format", but maybe this will help also.

-ej





More information about the Python-list mailing list