Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid Syntax calling "print" attribute

Tags:

python

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.

like image 458
Suman Bhandari Avatar asked Feb 25 '26 22:02

Suman Bhandari


1 Answers

You can try using getattr:

print getattr(res, 'print')
like image 167
Amber Avatar answered Feb 27 '26 12:02

Amber



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!