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


Messages In This Thread
Parsing and Editing a Structured Text File - by norsemanGrey - Jul-11-2018, 04:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Text parsing Arik 5 307 Mar-11-2024, 03:30 PM
Last Post: Gribouillis
  xml file editing with lxml.etree FlavioBueno 2 632 Jun-09-2023, 02:00 PM
Last Post: FlavioBueno
Video doing data treatment on a file import-parsing a variable EmBeck87 15 2,667 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 1,064 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  Regarding file editing dan86 12 2,449 Jun-29-2022, 07:13 PM
Last Post: dan86
  Modify values in XML file by data from text file (without parsing) Paqqno 2 1,575 Apr-13-2022, 06:02 AM
Last Post: Paqqno
  Editing text between two string from different lines Paqqno 1 1,287 Apr-06-2022, 10:34 PM
Last Post: BashBedlam
  Parsing xml file deletes whitespaces. How to avoid it? Paqqno 0 1,010 Apr-01-2022, 10:20 PM
Last Post: Paqqno
  Converted Pipe Delimited text file to CSV file atomxkai 4 6,842 Feb-11-2022, 12:38 AM
Last Post: atomxkai
  Parsing a syslog file ebolisa 11 4,001 Oct-10-2021, 05:15 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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