Python Forum
Parsing and Editing a Structured Text File - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Parsing and Editing a Structured Text File (/thread-11494.html)



Parsing and Editing a Structured Text File - norsemanGrey - Jul-11-2018

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"
)



RE: Parsing and Editing a Structured Text File - Larz60+ - Jul-11-2018

Even though the data you show is not python code, I added python tags as it just plain is easier to read.