0

I am getting this short of result when ever function processOutput(output) is called

output = {'LEND': '0', 'LINK': 'Xx', 'REND': '4', 'RULE': ''}

Suppose this function called thrice then result json should look like

{ 'object[0]' : {'LEND': '0', 'LINK': 'Xx', 'REND': '4', 'RULE': ''},
  'object[1]' : {'LEND': '0', 'LINK': 'Xa', 'REND': '3', 'RULE': 'two'},
  'object[2]' : {'LEND': '0', 'LINK': 'Xz', 'REND': '12', 'RULE': ''}
}

so that I can access json values in this way object[0]['LINK'] and so on

def printOutput(self, processed_output):
    #processed_output is output.
1
  • 1
    Will you please give what you tried ? Commented Nov 4, 2014 at 9:28

1 Answer 1

1

You should define a counter and output as globals and appending to output every results.

output = {}
c = 0

def printOutput(self, processed_output):
    global c, output
    output['object[%i]' % c] = processed_output
    c += 1
Sign up to request clarification or add additional context in comments.

4 Comments

thanks but it gives NameError: global name 'result' is not defined
Well, I don't see result in any part of the problem question, maybe you'll need to review your code.
output is result in my case
output is not result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.