I called an url that returns me a json object with an attribute called from. So when i want to get this in python i try:
object.from.username
$ python sample_app.py
File "sample_app.py", line 63
print comment.from.username
^
SyntaxError: invalid syntax
fromis a python keyword and should not be used as an attribute.Lucky for you, when using the
jsonlibrary that comes with python, JSON objects become dictionaries instead:For situations where you actually do have a object with a python keyword used as an attribute, you’d have to resort to using the
getattr()function instead: