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 7062671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:37:20+00:00 2026-05-28T04:37:20+00:00

I have an input text file which I am reading and storing everything in

  • 0

I have an input text file which I am reading and storing everything in a list. After that I’m splitting the list according to the specific text occurence in the list.

Here is the function.

import re
def readFile1(file1):
    f = file1.read().split('\n')
    #print f
    ctrlList1 = []
    mfcList1 = []

    for str in f:
        if re.search("MegaMon> mfc",str):
            print "splitting\n"
            break
        else:
            ctrlList1.append(str)

    print ctrlList1, "\n\n\n"

This works fine and saves ctrlList1 until the text megamon> mfc appears in the main list. But I want to save the lines after MegaMon> mfc in mfcList1. I am not able to do that.

I tried:

if not re.search("MegaMon> mfc", str):
   print "splitting\n"
   continue
else:
    mfcList1.append(str)

but this doesn’t seem to be working. I need to save the text file in two different lists. Any help would be appreciated.

  • 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-05-28T04:37:21+00:00Added an answer on May 28, 2026 at 4:37 am

    how about

     import re
     mfcList1, ctrlList1 = [],[]
     # read the whole file as a list of lines - its easier
     with open(file1, 'r') as f1:
         lines = f1.readlines()
    
     # for each line, search for your string. 
     # If you have found MegaMon append one mfcList1, else append ctrlList1
     foundMegaMon = False
     for line in lines:
         if re.search("MegaMon> mfc",line):
              foundMegaMon = True
         if foundMegaMon:
              mfcList1.append(line)
         else:
              ctrlList1.append(line)
    
    • 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 in my computer which I am reading form my
I have a text file input which contains data as below. How can I
I have a text file,which I use to input information into my application.The problem
Input: I have a LaTeX file, with plain text & math formulas. Desired output:
I have two input text boxes which are decimal. The sum of the two
I have an input text field, which has a value something by default, but
I have an input text field which has style: visibility: visible or style: visibility:
Supposedly I have this line in my text file which has the following format.
I am reading in a String from a text file which contains a date
I have a text file which was created using some Microsoft reporting tool. The

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.