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

  • Home
  • SEARCH
  • 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 4568440
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:04:35+00:00 2026-05-21T19:04:35+00:00

When I print the group print(a) the entire group is shown. When I save

  • 0

When I print the group “print(a)” the entire group is shown. When I save it to a text file “open(“sirs1.txt”, “w”).write(a)” only the last row is saved to the file.

import re

def main():
f = open('sirs.txt')
for lines in f:
    match = re.search('(AA|BB|CC|DD)......', lines)
    if match:
        a = match.group()
        print(a)
        open("sirs1.txt", "w").write(a)

How do I save the entire group to the text file.

  • 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-21T19:04:36+00:00Added an answer on May 21, 2026 at 7:04 pm

    nosklo is correct the main problem is that you are overwriting the whole file each time you write to it. mehmattski is also correct in that you will also need to explicitly add \n to each write in order to make the output file readable.

    Try this:

    enter code here
    
    import re
    
    def main():
      f = open('sirs.txt') 
      outputfile = open('sirs1.txt','w')
    
      for lines in f:
        match = re.search('(AA|BB|CC|DD)......', lines)
        if match:
          a = match.group()
          print(a)
          outputfile.write(a+"\n")
    
      f.close()
      outputfile.close()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

str = <test>0</test> print re.search(<.*?>, str).group() print re.search(>.*?<, str).group() >> <text> >> >0< How
I am trying to match a text in a file In [44]: with open(path)
$list_of_groups = array(FACULTY,STAFF); foreach ($list_of_groups as $i => $group) { $user_in_group = $adldap->user_ingroup($username,$group); print
I am trying to parse a gigantic log file (around 5 GB). I only
This is my code right now, import re matches = re.search(r'^%s\s*\((.*?)\)'%Hello, Hello(Hi())) print matches.group(1)
Please consider following snippet: <div class=row> <div class=span12> <div class=control-group> <label class=control-label>Person Name</label> <div
import re ip6 = 1234:0678:0000:0000:00cd:0000:0000:0000 zeroes = re.search((:?0000)+, ip6) print zeroes.group(0) :0000:0000 I'm trying
import re str=x8f8dL:s://www.qqq.zzz/iziv8ds8f8.dafidsao.dsfsi str2=re.match([a-zA-Z]*//([a-zA-Z]*),str) print str2.group() current result=> error expected => wwwqqqzzz I want
I understand the point of GROUP BY x . But how does GROUP BY
a=aaaaaa password: GOD hello world password is G0D hello match = re.match(^(?:.*(?:password\sis\s|password:\s)([a-zA-Z]*)\s.*)*$,a) print match.groups()

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.