I have a function which takes 2 parameters; a dict- _tInput, and a list- _order.
The aim is to be able to order the returned data for printing:
tOrderReq = [1, 4, 5, 2]
tReturnData = tOut(hInput[0], (tOrderReq))
print("%s %s %s %s" % tReturnData)
However I am getting the following error:
Traceback (most recent call last):
File "C:\local\mdev.py", line 76, in <module>
TypeError: not enough arguments for format string
I don't understand what I need to change to get this to work, I suspect it is something fairly basic that is showing through with my novice Python knowledge and my understanding of tuples, lists and dicts. The function is below-- incidentally, if there are any tips on how to improve this code, then i'm all ears.
def tOut(_tInput, _order=[]):
_tOutput = []
_tOutput.append(_tInput['id'])
_tOutput.append(_tInput['created_at'].encode('utf-8'))
_tOutput.append(_tInput['text'].encode('utf-8'))
_tOutput.append(_tInput['user']['id'])
_tOutput.append(_tInput['user']['screen_name'].encode('utf-8'))
_tOutput.append(_tInput['user']['name'].encode('utf-8'))
_tReturn = []
for x in _order:
_tReturn.append(_tOutput[x])
return (_tReturn)
Many thanks