Issue #1 resolved

Use pprint?

Saul Shanabrook
created an issue

Would it be possible to print the vars with pprint.pprint?

Right now with larger variable sets the output can get messy.

from show import show
show.set(where=True)
l = 'adsfgdfg'
j = {'dgfdsfg': 'sdfgsdfgsdf','asdf':123}
h =  {'image': 'http://www.canadanewyork.com/?page_id=2157',
  'old_url': '/press/2009/new-york-times-michael-williams',
  'title': 'The New York Times: Michael Williams'},
show(l, j, h)
'''
<stdin>:16:   l: 'adsfgdfg'  j: {'dgfdsfg': 'sdfgsdfgsdf', 'asdf': 123}  h: ({'image': 'http://www.canadanewyork.com/?page_id=2157', 'old_url': '/press/2009/new-york-times-michael-williams', 'title': 'The New York Times: Michael Williams'},)
'''

from pprint import pprint as p
p(show(l, j, h))
'''
<stdin>:18:   l: 'adsfgdfg'  j: {'dgfdsfg': 'sdfgsdfgsdf', 'asdf': 123}  h: ({'image': 'http://www.canadanewyork.com/?page_id=2157', 'old_url': '/press/2009/new-york-times-michael-williams', 'title': 'The New York Times: Michael Williams'},)
None
'''
show(p(l), p(j), p(h))
'''
'adsfgdfg'
{'asdf': 123, 'dgfdsfg': 'sdfgsdfgsdf'}
({'image': 'http://www.canadanewyork.com/?page_id=2157',
  'old_url': '/press/2009/new-york-times-michael-williams',
  'title': 'The New York Times: Michael Williams'},)
<stdin>:19:   p(l): None  p(j): None  p(h): None
'''

Comments (4)

  1. Jonathan Eunice repo owner

    I could provide a hook so that an arbitrary printing function of your choice could do the formatting. Would that work?

    Also, one way to make things neater, if you're going to show multiple variables on one line, is to set the separator to newline:

    show.set(sep='\n')
    show(l, j, h)
    

    yields:

    l: 'adsfgdfg'
    j: {'dgfdsfg': 'sdfgsdfgsdf', 'asdf': 123}
    h: ({'image': 'http://www.canadanewyork.com/?page_id=2157', 'old_url': '/press/2009/new-york-times-michael-williams', 'title': 'The New York Times: Michael Williams'},)
    

    (albeit with that last line wrapped).

  2. Jonathan Eunice repo owner

    Okay, it's done. As of version 0.62 (now on PyPI), show can use the pformat function from pprint to format its output. Or any other function, for that matter. E.g.:

    from pprint import pformat
    show.set(fmtfunc=pformat)
    

    You would still probably want to set the separator to \n. As a convenience, a show.prettyprint() method can set up pformat(), the \n separator, and (optionally) a pygments based syntax highlighter in one fell swoop:

    show.prettyprint()
    

    prettyprint() takes a few options for pformat and pygments.highlight. Or you can study the code under show.core.Show.prettyprint for a template on how to set up your alternate pretty print configuration.

  3. Jonathan Eunice repo owner

    Not sure what was going on, but the standard sudo pip install -U show was installing an old version, not the latest. So I have removed the old versions of show from PyPI, leaving only versions 0.63 and forward. It may be necessary to remove existing instances of show on your system to get the newest version to properly install. Not sure what fresh level of packaging hell this is. grumble

  4. Log in to comment