Python Forum
capturing multiline output for number of parameters
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
capturing multiline output for number of parameters
#1
I am using ttp template to parse a data from command line

I followed the following link while writing below code:
https://python-forum.io/thread-40584.html
https://ttp.readthedocs.io/en/latest/FAQ...ine-output

import json
from ttp import ttp

temp = """
<group>
System Info {{_start_}}
IPv4 configuration : {{ ipv4_configuration |  _exact_ }}
IPv6 configuration : {{ ipv6_configuration |  _exact_ }}

<group name="details">
Description  : {{ _start_ }}
{{description|_line_ | joinmatches("")}}
Modified details : {{ _start_ }}
{{modified_details|_line_|joinmatches("")}}
System Description : {{ _start_ }}
{{system_description|_line_|joinmatches("")}}
Technical Support : {{ _start_ }}
{{technical_support|_line_|joinmatches("")}}
{{ _end_ }}
</group>
<group name="ip_details">
  {{from}} {{to}}
</group>

</group>
"""

data_to_parse = """
===============================================================================
System Info
===============================================================================
IPv4 configuration : Disabled
IPv6 configuration : Enabled
Description        : #It is used to connect to the network
                      using the IPV6 and IPV4 which is
                      secure
Modified details   :  The code was modfied by jim corbett .Details
                      are [email protected]
System Description :  #Cisco IOS Software, Catalyst 1234 L3 Switch Software (cat1234e-ENTSERVICESK9-M), 
                       Version 1534.1(1)SG, RELEASE SOFTWARE (fc3)
Technical Support  :  http://www.cisco.com/techsupport Copyright (c) 1986-2012 by Cisco Systems, Inc.
                      Compiled Sun 15-Apr-12 02:35 by p
IP details         :
  From               To
  10.12.21.123       32.32.32.32
  10.12.21.123       32.32.32.32
  
"""
parser = ttp(data=data_to_parse, template=temp)
parser.parse()

result = json.loads(parser.result(format="json")[0])[0]
print(result)
My output is this:

Output:
[{'ip_details': [{'from': 'From', 'to': 'To'}, {'from': '10.12.21.123', 'to': '32.32.32.32'}, {'from': '10.12.21.123', 'to': '32.32.32.32'}], 'ipv4_configuration': 'Disabled', 'ipv6_configuration': 'Enabled'}]
My expected out put is like below:
Output:
{'ip_details': [{'from': '10.12.21.123', 'to': '32.32.32.32'}, {'from': '10.12.21.123', 'to': '32.32.32.32'}], 'ipv4_configuration': 'Disabled', 'ipv6_configuration': 'Enabled',"description" :"#It is used to connect to the networkusing the IPV6 and IPV4 which is secure","modified_details":"The code was modfied by jim corbett .Details are [email protected]","system_description":"#Cisco IOS Software, Catalyst 1234 L3 Switch Software (cat1234e-ENTSERVICESK9-M), Version 1534.1(1)SG, RELEASE SOFTWARE (fc3)","technical_support":"http://www.cisco.com/techsupport Copyright (c) 1986-2012 by Cisco Systems, Inc.Compiled Sun 15-Apr-12 02:35 by p"}
Please shed light on how to proceed
Reply
#2
Quit starting new posts for the same question, and stop spoon-feeding the question.
Reply
#3
The reason i added {{_end__}} was as it explicitly indicates end of the group.
Reply
#4
.....
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Capturing BS4 values into DF and writing to CSV cubangt 18 1,971 Sep-05-2023, 01:57 PM
Last Post: cubangt
  Formatting float number output barryjo 2 931 May-04-2023, 02:04 PM
Last Post: barryjo
  Json filter is not capturing desired key/element mrapple2020 1 1,144 Nov-24-2022, 09:22 AM
Last Post: ibreeden
  Search text in PDF and output its page number. atomxkai 21 9,004 Jan-21-2022, 06:20 AM
Last Post: snippsat
  Presenting multiline data into single line aaronbuhu 1 1,812 Aug-05-2021, 10:57 AM
Last Post: jamesaarr
  How to input & output parameters from command line argument shantanu97 1 2,584 Apr-13-2021, 02:12 PM
Last Post: Larz60+
  RuntimeError: Optimal parameters not found: Number of calls to function has reached m bntayfur 0 6,157 Aug-05-2020, 04:41 PM
Last Post: bntayfur
  Multiline comments macfanpl 6 2,777 May-07-2020, 08:14 PM
Last Post: macfanpl
  How can I create a multiline input in ipython? DataMower 3 4,389 Oct-28-2019, 08:50 PM
Last Post: DataMower
  Capturing inputs values from internal python script limors11 11 5,215 Jun-16-2019, 05:05 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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