Make toPrettyString a little prettier and more flexible

Existing unit tests still pass, though I haven't added any new ones specifically to test this output formatting change; I ran unittest & verified "by eye" that the output was as expected.