1

I am using Pyshark to parse a PCAP. There are some object which name begin with digit say pkt.diameter.3gpp_reporting_reason. I'm not able to refer to this object, because I get an error "invalid decimal literal".

Any ideas how to retrieve the attribute pkt.diameter.3gpp_reporting_reason.all_fields?

Screenshot of error message

wovano
  • 4,543
  • 5
  • 22
  • 49
Mak Alex
  • 11
  • 2
  • 2
    When you have code, please create a minimally reproducible example and add that code to your question. – cherrywoods Oct 17 '22 at 13:14
  • Welcome to Stack Overflow. Please don't paste code, errors or other text as image. Instead copy-paste the text and make sure to format it correctly. Thanks. – wovano Oct 18 '22 at 19:14

1 Answers1

2

The issue is that names starting with digits aren't valid identifiers in python. While python is reading your code, it things you are entering a number.

To still access the attribute, use getattr.

getattr(pkt.diameter, "3gpp_reporting_reason").all_fields
cherrywoods
  • 1,284
  • 1
  • 7
  • 18