0

Here is my newest baby, the pretty.py module, born today, which I start to use instead of pprint module.

Reason to make this (in addition to that it is possible to do) is that I had this problem, sorry long, LONG example:

UPDATE: take out the

`or j`

that was by mistake left from development.

Example is starting from line 43 from different run with longer a variable defined before expressions.

```
## The problem with prettyprint module
>>> a=['a','b','c']*4
>>> pprint(a)
['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c']
>>> a=['a','b','c']*10
>>> pprint(a)
['a',
'b',
'c',
'a',
'b',
'c',
'a',
'b',
'c',
'a',
'b',
'c',
'a',
'b',
'c',
'a',
'b',
'c',
'a',
'b',
'c',
'a',
'b',
'c',
'a',
'b',
'c',
'a',
'b',
'c']
>>>
## i like this better
>> pretty.ppr(a)
['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c']
## more hierarchy
>>> a[4]=[['a','b','c']]*2
>>> a
['a', 'b', 'c', 'a', [['a', 'b', 'c'], ['a', 'b', 'c']], 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c']
## lets first show my way
>>> pretty.ppr(a)
['a', 'b', 'c', 'a',
[
['a', 'b', 'c'],
['a', 'b', 'c']], 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c']
## pprint way
>>> pprint(a)
['a',
'b',
'c',
'a',
[['a', 'b', 'c'], ['a', 'b', 'c']],
'c',
'a',
'b',
'c',
'a',
'b',
'c',
'a',
'b',
'c',
'a',
'b',
'c',
'a',
'b',
'c',
'a',
'b',
'c',
'a',
'b',
'c',
'a',
'b',
'c',
'a',
'b',
'c',
'a',
'b',
'c',
'a',
'b',
'c',
'a',
'b',
'c',
'a',
'b',
'c',
'a',
'b',
'c']
### more use examples
>>> ppr(4*[(['a','b','c','d'],)*4])
[
(
['a','b','c','d'],
['a','b','c','d'],
['a','b','c','d'],
['a','b','c','d']),
(
['a','b','c','d'],
['a','b','c','d'],
['a','b','c','d'],
['a','b','c','d']),
(
['a','b','c','d'],
['a','b','c','d'],
['a','b','c','d'],
['a','b','c','d']),
(
['a','b','c','d'],
['a','b','c','d'],
['a','b','c','d'],
['a','b','c','d'])]
## You can not say like this
>>> ppr(4*[([None*4],)*4])
Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
ppr(4*[([None*4],)*4])
TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'
## You must say not like this
>>> ppr(4*[([[None]*4],)*4])
[
(
[
[None,None,None,None]],
[
[None,None,None,None]],
[
[None,None,None,None]],
[
[None,None,None,None]]),
(
[
[None,None,None,None]],
[
[None,None,None,None]],
[
[None,None,None,None]],
[
[None,None,None,None]]),
(
[
[None,None,None,None]],
[
[None,None,None,None]],
[
[None,None,None,None]],
[
[None,None,None,None]]),
(
[
[None,None,None,None]],
[
[None,None,None,None]],
[
[None,None,None,None]],
[
[None,None,None,None]])]
## but like this
>>> ppr(4*[([None]*4,)*4])
[
(
[None,None,None,None],
[None,None,None,None],
[None,None,None,None],
[None,None,None,None]),
(
[None,None,None,None],
[None,None,None,None],
[None,None,None,None],
[None,None,None,None]),
(
[None,None,None,None],
[None,None,None,None],
[None,None,None,None],
[None,None,None,None]),
(
[None,None,None,None],
[None,None,None,None],
[None,None,None,None],
[None,None,None,None])]
## Success!
```

*Edited
by pyTony*: Explanation of inconsistency