Bottom Page

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"
)
Quote
#2
Even though the data you show is not python code, I added python tags as it just plain is easier to read.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Code Editing Help Rememberthecreed 2 230 Feb-08-2020, 09:56 AM
Last Post: Rememberthecreed
  Rename file from value in text file Nuge93 1 170 Jan-20-2020, 03:50 PM
Last Post: gruntfutuk
  pdf file processing: how to "Enable Editing" Pavel_47 4 276 Dec-04-2019, 10:00 AM
Last Post: Pavel_47
  help parsing file aslezak 2 342 Oct-22-2019, 03:51 PM
Last Post: aslezak
  Indexed position editing of a lst ShruthiLS 4 255 Sep-26-2019, 09:23 AM
Last Post: perfringo
  Python Script for parsing dictionary values from yaml file pawan6782 3 892 Sep-04-2019, 07:21 PM
Last Post: pawan6782
  Trying to make column based file from text file scor1pion 7 521 Jul-16-2019, 02:43 PM
Last Post: scor1pion
  How best to format text in a simple text file? Pedroski55 2 808 Jun-14-2019, 06:07 AM
Last Post: noisefloor
  Parsing an MBOX file Oliver 1 1,970 May-26-2019, 07:12 AM
Last Post: heiner55
  parsing complex text file anna 1 519 Apr-10-2019, 09:54 PM
Last Post: Larz60+

Forum Jump:


Users browsing this thread: 1 Guest(s)