Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ttp template
#2
I figured out what it was doing right away, but it took a while to find in the documentation. Unless told otherwise, ttd replace digits with \d, so 'IPV4 configuration' and 'IPv6 configuration' make identical patterns. I finally found it under Indicators.

https://ttp.readthedocs.io/en/latest/Mat...ght=digits

_exact_
{{ name | _exact_ }}

By default, the parser will replace all digits in a template with the ‘d+’ pattern. However, if _exact_ is present in any match variable within a line, digits will remain unchanged and parsed as is.

This is an important consideration for when a pattern contains numbers.

Your pattern should be:
import json
from ttp import ttp

temp = """
System Info
IPv4 configuration : {{ ipv4_configuration |  _exact_ }}
IPv6 configuration : {{ ipv6_configuration |  _exact_ }}
"""

data_to_parse = """
System Info
IPv4 configuration : Disabled
IPv6 configuration : Enabled
"""
parser = ttp(data=data_to_parse, template=temp)
parser.parse()

result = json.loads(parser.result(format="json")[0])[0]
print(result)
jss likes this post
Reply


Messages In This Thread
ttp template - by jss - Aug-22-2023, 07:24 PM
RE: ttp template - by deanhystad - Aug-22-2023, 11:50 PM
RE: ttp template - by jss - Aug-23-2023, 05:26 AM
RE: ttp template - by jss - Aug-23-2023, 08:10 PM
RE: ttp template - by deanhystad - Aug-23-2023, 08:58 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020