I'm working on a Python(3.6) project in which I need to parse some text files from a directory structure.
Directory structure as:
--easy(root dir)
----sub_dir
-------another_sub_dir
-----------description( another sub dir)
------------------ description.txt (file)
I need to iterate through all of the descriptions.txt files from subdirectories and then parse them into the database.
the description.txt file is formatted in a standard formate as:
Start with a text paragraph then we have Input, output, constraints, Example > input, output and Explanation headings. We need to save the description.txt file in the database as these headings will convert into a DB table column.
I have tried to iterate through the directory structure to find all description.txt files as:
import os
for root, dirs, files in os.walk(os.path.join('easy')):
for file in files:
if file.endswith('description.txt'):
print(os.path.join(root, file))
In this way we can get all descriptions.txt files but how we can parse them by using headings inside that text file and save them into the database.
How can we accomplish that? Hlep me, please!
Thanks in advance!