0

I'm trying to compile some (minor) statistical data from a Telegram group chat, and to do that, I'm scanning a JSON file of the chat. When I run main.py, I get SyntaxError: invalid syntax because Python doesn't seem to accept using "from" as a property, which is something that I need to do in order to get the data I need.

Here is my code:

import json
from types import SimpleNamespace

with open('result.json') as f:
  data = json.load(f, object_hook=lambda d: SimpleNamespace(**d))

leetkrew = data.chats.list[0]

for message in leetkrew.messages:
    if "search for this text" in message.text:
        print(message.from)

What is the best way to work around this? I can't change the name of the "from" property as this JSON file is pretty massive.

Alex
  • 19
  • 5

0 Answers0