Python Forum
Parsing and Editing a Structured Text File
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Parsing and Editing a Structured Text File
#1
Hi. First I want to say that I'm kind of new to Python, but I have been through some basics so I am not beginning from scratch :)

My company is using structured configuration text files to save configurations in parts of their software. Although for small changes it is possible to change the configurations through the software it would be preferable to do some of this by editing the text file and load it to the software afterwards. I want to use Python to read the configuration file and export certain parameters (depending on user input) to a tab separated text file or similar that can be viewed and edited in Excel from where one can add, remove or edit parts of the parameters. Then, using the updated tab separated text file, update the original configuration file.

The configuration file that is used with our software is structured something like the below example. It is separated into blocks separated with ( ) and identified by keywords. For instance, in the example there are two drivers with some general info, driver configuration and some IO points each that all has additional details. In a typical configuration file there will be several thousand lines of similar stuff, which would be suitable for editing in Excel or similar.

I was wondering if anyone have any tips on how I might get started with this. Perhaps I am not taking the best approach with my above idea and you have some other suggestion on how I should go about this. Maybe there are some Python packages or other resources that can help me along with this. Any input is highly appreciated Smile

<software version etc.>
( Driver
Name = "Driver 12"
Info1 = "stuff"
Info2 = "stuff"
Info3 = 453
)
( DriverConfig
Info1 = "more stuff"
Info2 = "more stuff"
Info3 = 33
)
( Point
No = 1
Index = 43
Tag = "some tag"
)
( PointDetails
Info1 = "some details"
Info2 = "some details"
)
( Point
No = 2
Index = 86
Tag = "some tag"
)
( PointDetails
Info1 = "some details"
Info2 = "some details"
)
( Point
No = 3
Index = 77
Tag = "some tag"
)
( PointDetails
Info1 = "some details"
Info2 = "some details"
)
( Driver
Name = "Driver 563"
Info1 = "stuff"
Info2 = "stuff"
Info3 = 453
)
( DriverConfig
Info1 = "more stuff"
Info2 = "more stuff"
Info3 = 33
)
( Point
No = 1
Index = 43
Tag = "some tag"
)
( PointDetails
Info1 = "some details"
Info2 = "some details"
)
( Point
No = 2
Index = 86
Tag = "some tag"
)
( PointDetails
Info1 = "some details"
Info2 = "some details"
)
( Point
No = 3
Index = 77
Tag = "some tag"
)
( PointDetails
Info1 = "some details"
Info2 = "some details"
)
Reply
#2
Even though the data you show is not python code, I added python tags as it just plain is easier to read.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  parsing a tree of text first the right most aligned blocks of text and so on arvindikchari 2 806 Nov-21-2024, 01:42 AM
Last Post: BashBedlam
  Reading an ASCII text file and parsing data... oradba4u 2 1,465 Jun-08-2024, 12:41 AM
Last Post: oradba4u
  Text parsing Arik 5 1,702 Mar-11-2024, 03:30 PM
Last Post: Gribouillis
  xml file editing with lxml.etree FlavioBueno 2 2,224 Jun-09-2023, 02:00 PM
Last Post: FlavioBueno
Video doing data treatment on a file import-parsing a variable EmBeck87 15 5,715 Apr-17-2023, 06:54 PM
Last Post: EmBeck87
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 2,039 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  Need help editing a PDF omar 4 2,021 Oct-22-2022, 08:52 PM
Last Post: Larz60+
  Regarding file editing dan86 12 4,422 Jun-29-2022, 07:13 PM
Last Post: dan86
  Modify values in XML file by data from text file (without parsing) Paqqno 2 3,190 Apr-13-2022, 06:02 AM
Last Post: Paqqno
  Editing text between two string from different lines Paqqno 1 1,837 Apr-06-2022, 10:34 PM
Last Post: BashBedlam

Forum Jump:

User Panel Messages

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