Whenever PowerShell displays its objects, it formats them in a nice pretty manner in the monospaced console, e.g.:
> ps
Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
------- ------ ----- ----- ----- ------ -- -----------
101 5 1284 3656 32 0.03 3876 alg
257 7 4856 10228 69 0.67 872 asghost
101 4 3080 4696 38 0.36 1744 atiptaxx
179 7 5568 7008 54 0.22 716 BTSTAC~1
...
Is there a similar library in Python or do I get to make one?
I think python texttable module does exactly what you were looking for.
For further information.
There is a pprint
module which does a little bit of that. It's not as nice as your example but it does at least try to print 2-D and recursive data structures more intelligently than str()
.
The pprint module provides a capability to “pretty-print” arbitrary Python data structures in a form which can be used as input to the interpreter. If the formatted structures include objects which are not fundamental Python types, the representation may not be loadable. This may be the case if objects such as files, sockets, classes, or instances are included, as well as many other built-in objects which are not representable as Python constants.
Then there is numpy
module which is targeted at mathematic and scientific computing, but is also pretty darn good at displaying matrices:
>>> from numpy import arange
>>> b = arange(12).reshape(4,3) # 2d array
>>> print b
[[ 0 1 2]
[ 3 4 5]
[ 6 7 8]
[ 9 10 11]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With