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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:40:24+00:00 2026-06-07T20:40:24+00:00

this is my first day with python and i’m stuck. I have a file

  • 0

this is my first day with python and i’m stuck. I have a file which content looks like this:

  • Declaration //skip
  • foo bar //shown as option
  • Labels //skip
  • 1 foo
  • 2 foo
  • 3 bar
  • 4 foo bar
  • …
  • 23546477 bar bar bar bar foo

If the user choose foo, I just want to return 1,2, 4 and 23546477 and write in a file:

  • Target 1
  • Target 2
  • Target 4
  • Target 23546477

This is what I have come up so far:

import sys
import re

def merge():

   if (len(sys.argv) > 1):
    labfile = sys.argv[1]
    f = open(labfile, 'r')
    f.readline()
    string = f.readline()
    print "Possible Target States:"
    print string
    var = raw_input("Choose Target States: ")
    print "you entered ", var
    f.readline()
    words = var.split()
    for line in f.readlines():
      for word in words:
        if word in line:
          m = re.match("\d+", line)
          print m
          //get the first number and store it in a list or an array or something else

    f.close()

merge() 

unfortunately it is not working – I see lines like <_sre.SRE_Match object at 0x7fce496c0100> instead of the output I want.

  • 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-07T20:40:25+00:00Added an answer on June 7, 2026 at 8:40 pm

    You want to do (at least):

    if m:  #only execute this if a match was found
       print m.group()  #m.group() is the portion of the string that matches your regex.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have two arrays like this first array Array ( [0228] => Array (
I'm new to python and have been trying to figure this out all day.
I am trying to install python on windows, and this is my first day
This is my first day to design UI using WPF. I have looked up
Today's my first day with Flex and FlashDevelop. In my ActionScript file, I have
I am currently getting first day Of this week and last week values with
I'm using this line to get the beginning time of the first day of
Using Dozer to map two objects, I have: /** /* This first class uses
I'm a PHP guy on my first day in Python-land, trying to convert a
I have strings that look like these: {server}_{date:YYYYMMDD}{int:######} {server}_{date:MON DAY YYYY}{int:######} ...plus more, in

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.