Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8468569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:58:18+00:00 2026-06-10T15:58:18+00:00

I have data in text file and I need to store it in database

  • 0

I have data in text file and I need to store it in database and now I little bit confused how to do it easier.

Here is an example of my data:

a: text1
b: text2
c: text3
blah blah not necessary text
a: text4
b: text5
c: text6
etc

So can you help me to parse this data.
I already done next code

import urllib2 as ur

def getPageData(url):
    return ur.urlopen(url).readlines()

checkList = ['a', 'b', 'c']

if __name__ == '__main__':
    textList = getPageData(url)
    res = []
    for i in textList:
        for y in checkList:
            if y in i:
                print i

I create a table in base something like

id | a varchar | b varchar | c varchar |

and I expect next result

id | a varchar | b varchar | c varchar |
1  | text1     | text2     | text3     |
2  | text4     | text5     | text6     |
n  | text      | text      | text      |

if read text file line by line how can I divide this text to logical blocks, for example I get a,b,c create dictionary with this data, and next when this block ends I append dictionary to list, and after that I have list of dict to store it to base. But I little bit confused how to create this list with this dictionary what I need to check and how to avoid unnecessary data in it? Is there more elegant way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:58:20+00:00Added an answer on June 10, 2026 at 3:58 pm

    I’d split on the : colon and test if the first part is in the set of allowed prefixes:

    checkList = set(['a', 'b', 'c'])
    
    for i in textList:
        check, rest = i.split(':', 1)
        if check.strip() not in checkList:
            continue
        data = rest.strip()
        # insert data into database; check is your column name.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file which contains data seperated by '|'. I need to
I have few text and excel file, from which I need to import data
i have created a datatable dynamically from a text file .Now i need to
I have created a few little programs that export data to a text file
I have a text data file that I likely will read with readLines .
I have to write huge data in text[csv] file. I used BufferedWriter to write
This is the data in my text file: (I have shown 10 rows out
We have some C# code that reads data from a text file using a
I have Text file that contains data separated with a comma , . How
I have a text file that contains cached data in JSON format. I'm trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.