Suman Bhandari
Suman Bhandari

Reputation: 91

Invalid Syntax calling "print" attribute

This is the response received from third party API

response = [{ print = True },{print = False}]

Now if I access the "print" attribute of that response, it give me with syntax error

for res in response:
    print res.print

SyntaxError('invalid syntax', '/home/suman/workspace/kioskinterface/apis/igt.py', 104, 38, '
print ticket.print\n')

The problem must be because of the reserved word. Is there any way around to access "print" attribute from the response.

Upvotes: 3

Views: 190

Answers (1)

Amber
Amber

Reputation: 527073

You can try using getattr:

print getattr(res, 'print')

Upvotes: 1

Related Questions