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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:19:51+00:00 2026-06-12T22:19:51+00:00

I am just testing out a small python script of which I will use

  • 0

I am just testing out a small python script of which I will use part in a larger script. Basically I am trying to lookup a field in a CSV file (where it contains a regex), and use this in a regex test. The reason is (part of a very wierd use-case) and will enable easier maintenance of a CSV file instead of the script. Is there something I am missing with the following….

test.csv:

field0,field1,field2
foo,bar,"\d+\.\d+"
bar,foo,"\w+"

test.py (extra print‘s used for testing):

import sys
import re
import csv

input = sys.argv[1]
print input

reader = csv.reader(open('test.csv','rb'), delimiter=',', quotechar="\"")
for row in reader:
        print row
        value = row[0]
        print value
        if value in input:
                regex = row[2]
                print regex

                pat = re.compile(regex)
                test = re.match(pat,input)
                out = test.group(1)
                print out

If I pass a value like “foo blah 38902462986.328946239846” to the script, I would expect this to pick up that it contains foo and then use the regex, \d+\.\d+, to extract 38902462986.328946239846. However when I run the script I get the following:

foo blah 0920390239.90239029
['field0', 'field1', 'field2']
field0
['foo', 'bar', '\\d+\\.\\d+']
foo
\d+\.\d+
Traceback (most recent call last):
  File "reg.py", line 19, in <module>
    out = test.group(1)
AttributeError: 'NoneType' object has no attribute 'group'

Not sure what’s going on really.

P.S Python is a big world and still learning.

  • 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-12T22:19:52+00:00Added an answer on June 12, 2026 at 10:19 pm

    According to the docs re.match matches at the beginning of the input string. You need to use re.search. Also, there’s no need to compile if you don’t reuse them afterwards. Just say test = re.search(regex, input).

    In the regular expressions in your example you don’t have any capture groups, so test.group(1) is going to fail, even if there’s a match in the input.

    import sys
    import re
    import csv
    
    input = 'foo blah 38902462986.328946239846'
    
    reader = csv.reader(open('test.csv','rb'), delimiter=',', quotechar="\"")
    for row in reader:
        value = row[0]
        if value in input:
            regex = row[2]
            test = re.search(regex, input)
            print input[test.start():test.end()]
    

    Prints:

    38902462986.328946239846
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm just testing out the csv component in python, and i am having some
I am just getting started with JS Unit Testing and am trying out qUnit.
I have just started out with testing some php mvc framework In it, it
I am just testing and trying to learn how assembler works with C. So
I'm just starting out with unit testing in C#. I have been reading about
I'm just doing a small program. It's an address book which has four options:
Just testing out some special regex characters and just came across some behaviour I
I was just testing Towers of Hanoi problem in Java and I ran the
I'm just testing a simple databind expression with: <div> Now: <%# DateTime.Now.ToString()%> </div> According
I am just testing an app to get data off our web server, previously

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.