I have an issue printing things efficiently. I return each rows from a function. What is the most efficient way to print all the row column values for debugging?
(Also it does not print properly the last item (when there is a loop) where it is a list of object name. Can somebody teach the way to do it correctly? )
def get_address(address, filter=None, limit=None, offset=None, api_code=None):
resource = 'address/{0}?format=json'.format(address)
if filter is not None:
if isinstance(filter, FilterType):
resource += '&filter=' + str(filter.value)
else:
raise ValueError('Filter must be of FilterType enum')
if limit is not None:
resource += '&limit=' + str(limit)
if offset is not None:
resource += '&offset=' + str(offset)
if api_code is not None:
resource += '&api_code=' + api_code
response = util.call_api(resource)
json_response = json.loads(response)
return Address(json_response)
class Address:
def __init__(self, a):
self.hash160 = a['hash160']
self.address = a['address']
self.n_tx = a['n_tx']
self.total_received = a['total_received']
self.total_sent = a['total_sent']
self.final_balance = a['final_balance']
self.transactions = [Transaction(tx) for tx in a['txs']]
def test_getAddressByBase58(address):
address = get_address(address)
a = address.hash160
b = address.final_balance
c = address.total_received
d = address.total_sent
e = address.n_tx
f = address.transactions
return a,b,c,d,e,f
print(test_getAddressByBase58('********************************'))
output:
('4428937923472494379ad36a', 0, 532398745780, 5192730, 13, [<explorer.Transaction object at 0x10d08bfd0>, <explorer.Transaction object at 0x10e56c048>, <explorer.Transaction object at 0x10e56c160>, <explorer.Transaction object at 0x10e577860>, <explorer.Transaction object at 0x10e577f98>, <explorer.Transaction object at 0x10e57a0f0>, <explorer.Transaction object at 0x10e5877f0>, <explorer.Transaction object at 0x10e587ac8>, <explorer.Transaction object at 0x10e587be0>, <explorer.Transaction object at 0x10e596320>, <explorer.Transaction object at 0x10e596cf8>, <explorer.Transaction object at 0x10e596e10>, <explorer.Transaction object at 0x10e599390>, <explorer.Transaction object at 0x10e5a6a90>, <explorer.Transaction object at 0x10e5a6ba8>, <explorer.Transaction object at 0x10e5b42e8>, <explorer.Transaction object at 0x10e5b4908>, <explorer.Transaction object at 0x10e5b4a20>, <explorer.Transaction object at 0x10e5c3160>, <explorer.Transaction object at 0x10e5c3240>, <explorer.Transaction object at 0x10e5c3320>, <explorer.Transaction object at 0x10e5c3400>, <explorer.Transaction object at 0x10e5c34e0>, <explorer.Transaction object at 0x10e5cfbe0>, <explorer.Transaction object at 0x10e5cfcf8>, <explorer.Transaction object at 0x10e5de438>, <explorer.Transaction object at 0x10e5de630>, <explorer.Transaction object at 0x10e5de710>, <explorer.Transaction object at 0x10e5eae10>, <explorer.Transaction object at 0x10e5eaef0>, <explorer.Transaction object at 0x10e5ee3c8>, <explorer.Transaction object at 0x10e5ee4e0>, <explorer.Transaction object at 0x10e5f9be0>, <explorer.Transaction object at 0x10e5f9cf8>, <explorer.Transaction object at 0x10e5f9dd8>, <explorer.Transaction object at 0x10e5fdcf8>, <explorer.Transaction object at 0x10e5fde10>, <explorer.Transaction object at 0x10e60c550>, <explorer.Transaction object at 0x10e617c50>, <explorer.Transaction object at 0x10e617d30>, <explorer.Transaction object at 0x10e617e80>, <explorer.Transaction object at 0x10e617f60>, <explorer.Transaction object at 0x10e61b0f0>, <explorer.Transaction object at 0x10e61b1d0>, <explorer.Transaction object at 0x10e61b2e8>, <explorer.Transaction object at 0x10e6279e8>, <explorer.Transaction object at 0x10e62d0b8>, <explorer.Transaction object at 0x10e62d198>, <explorer.Transaction object at 0x10e62d2b0>, <explorer.Transaction object at 0x10e62d3c8>])
EDIT:
I tried the following code in the class.
class Address:
def __init__(self, a):
self.hash160 = a['hash160']
self.address = a['address']
self.n_tx = a['n_tx']
self.total_received = a['total_received']
self.total_sent = a['total_sent']
self.final_balance = a['final_balance']
self.transactions = [Transaction(tx) for tx in a['txs']]
def __repr__(self):
return (
self.hash160,
self.address,
self.n_tx,
self.total_received,
self.total_sent,
self.final_balance,
self.transactions)
BUt it returned the error:
Traceback (most recent call last):
File "test_explo.py", line 11, in <module>
print(get_address('*************************'))
TypeError: __str__ returned non-string (type tuple)
Why is this mentioning str? I am not using it.