Skip to content

Commit

Permalink
Merge pull request #99 from willplaehn/ordereddict
Browse files Browse the repository at this point in the history
print OrderedDict nicely
  • Loading branch information
filipeximenes committed Jan 14, 2016
2 parents d5746ea + 406074b commit d9201da
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions tapioca/tapioca.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import requests
import webbrowser

import json
from collections import OrderedDict

from .exceptions import ResponseProcessException


Expand Down Expand Up @@ -129,11 +132,16 @@ def __dir__(self):
return []

def __str__(self):
import pprint
pp = pprint.PrettyPrinter(indent=4)
return ("<{} object\n"
"{}>").format(
self.__class__.__name__, pp.pformat(self._data))
if type(self._data) == OrderedDict:
return ("<{} object, printing as dict:\n"
"{}>").format(
self.__class__.__name__, json.dumps(self._data, indent=4))
else:
import pprint
pp = pprint.PrettyPrinter(indent=4)
return ("<{} object\n"
"{}>").format(
self.__class__.__name__, pp.pformat(self._data))

def _repr_pretty_(self, p, cycle):
p.text(self.__str__())
Expand Down

0 comments on commit d9201da

Please sign in to comment.