Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: Parse Text files and save data against some headings in database

Abdul Rehman:

I'm working on a python(3.6) project in which I need to Parse a text file,

My specific problem is: My text file has some Headings like Examples, Input, Output, Explanations, Notes I need to parse this file and take input & Output headings after Examples headings and write them at end of this file mean after Notes heading and save the file.

Here's I'm trying to get the next line of Examples line:


count = 0
for root, dirs, files in os.walk(os.path.join('description2code_current')):
for file in files:
if file.endswith('description.txt'):
old_name = os.path.join(os.path.abspath(root), file)
print('File Path ````` is: ', old_name)
rf = open(old_name, "r")
lines = rf.readline()
# print(lines)
for line in lines:
line = line.strip()
if line == 'Examples':
print(line)

How can I make that change into my file and then parse it again to save data against these headings into my database?

Help me, please!

Thanks in advance!



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: Parse Text files and save data against some headings in database

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×