help regarding re.search

Sagar Neve nevesagar at gmail.com
Thu Sep 15 00:54:13 EDT 2011


I figured it out with the sample program I gave you.   It was my mistake;
However, the same thing with same values is not working in my main program.

Here is what I am trying: The program traverses with correct values upto the
if condition we just discussed; but fails to quality that if condition;
instead it should qualify.


        for key in dictionary:
            m=re.search(key, url)
            if m !=None:
                values=dictionary[key]
                for v in values:
                    v_array=v.split(',')
                    Man_Param=v_array[4]
                    Opt_Param1=v_array[5]
                    Opt_Param2=v_array[6]
                    Cat=v_array[1]
                    Man_Param=re.sub(r'"(?P<dn>.*?)"','\g<dn>', Man_Param)
                    Opt_Param1=re.sub(r'"(?P<dn>.*?)"','\g<dn>', Opt_Param1)
                    Opt_Param2=re.sub(r'"(?P<dn>.*?)"','\g<dn>', Opt_Param2)
                    Cat=re.sub(r'"(?P<dn>.*?)"','\g<dn>', Cat)
                    Cat=re.sub(r':','_', Cat)
                    Cat=re.sub(r' ','_', Cat)
                    print "hello..Man_Param=%s,Opt_Param1=%s,
Opt_Param2=%s\n" %(Man_Param,Opt_Param1,Opt_Param2)
                    #sys.exit(1)
                    if len(Opt_Param1):
                        if len(Opt_Param2):
                            #if (re.search(Man_Param,url) and
re.search(Opt_Param1,url) and re.search(Opt_Param2,url) ):
                            print url
                           * if (Man_Param in url):#and (Opt_Param1 in url)
and (Opt_Param2 in url):    *
                                print "all are found..\n"
                                sys.exit(1)
                                if((int(cl) < 5000 or int(rc) == 206) and
re.match(r"AS_D",Cat) ):
                                    Cat= Cat + "_cont"
                                foutname = "output" + "/" + Cat +"." +
str(cnt)
                                fout =open(foutname, "a")
                                fout.write(line)
                                fout.close
                            else:
                                print "here\n";
                                sys.exit(1)




On Thu, Sep 15, 2011 at 10:19 AM, Chris Angelico <rosuav at gmail.com> wrote:

> On Thu, Sep 15, 2011 at 2:41 PM, Sagar Neve <nevesagar at gmail.com> wrote:
> > ./sample.py: line 9: syntax error near unexpected token `:'
> > ./sample.py: line 9: `if (Opt_Param2 in url):    '
> >
>
> It worked for me in Python 3.2. What version of Python are you using?
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110915/cf6063a6/attachment-0001.html>


More information about the Python-list mailing list