Re: help regarding re.search

2011-09-15 Thread Sagar Neve
Hey
Thanks.

I just resolved it and yes you are right there was a (hidden) new-line to
it. I found it in a crude way of putting dots before and after.  I was to
post about it here and saw your message.

I was not knowing about %r. Thanks for that. Thats a good addition to my
knowledge.

Thanks a bunch of all. My day is saved.

Best Regards,
Sagar Neve.


On Thu, Sep 15, 2011 at 2:35 PM, Gelonida N  wrote:

> Hi Sagar,
>
> In order to be able to help you I propose following:
>
> On 09/15/2011 06:54 AM, Sagar Neve wrote:
> . . .
> > print "hello..Man_Param=%s,Opt_Param1=%s,
> > Opt_Param2=%s\n" %(Man_Param,Opt_Param1,Opt_Param2)
>
> Change above line into
>
> > print "hello..Man_Param=%r,Opt_Param1=%r,
> > Opt_Param2=%r\n" %(Man_Param,Opt_Param1,Opt_Param2)
>
>
> and show us the output of an example which is NOT working.
>
> printing with '%r" might help to show some 'hidden special characters'
>
>
>
>
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help regarding re.search

2011-09-15 Thread Gelonida N
Hi Sagar,

In order to be able to help you I propose following:

On 09/15/2011 06:54 AM, Sagar Neve wrote:
. . .
> print "hello..Man_Param=%s,Opt_Param1=%s,
> Opt_Param2=%s\n" %(Man_Param,Opt_Param1,Opt_Param2)

Change above line into

> print "hello..Man_Param=%r,Opt_Param1=%r,
> Opt_Param2=%r\n" %(Man_Param,Opt_Param1,Opt_Param2)


and show us the output of an example which is NOT working.

printing with '%r" might help to show some 'hidden special characters'







-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help regarding re.search

2011-09-14 Thread Sagar Neve
Yes. It is been resolved now for the sample program. however, as mentioned
in other post. It is not working in the main program


On Thu, Sep 15, 2011 at 10:25 AM, Kushal Kumaran <
kushal.kumaran+pyt...@gmail.com> wrote:

> On Thu, Sep 15, 2011 at 10:11 AM, Sagar Neve  wrote:
> > Here is the code
> >
> >
> > url="
> http://xy.yz.com/us/r1000/012/Purple/b1/c6/e2/mzm.dxkjsfbl..d2.dpkg.ipa";
> >
> > Man_Param="/us/r1000"
> > Opt_Param1="Purple"
> > Opt_Param2="dpkg.ipa"
> >
> > if (Opt_Param2 in url):
> > print "hello."
> > else:
> > print "bye."
> >
> > It  gives me:
> >
> > ./sample.py: line 9: syntax error near unexpected token `:'
> > ./sample.py: line 9: `if (Opt_Param2 in url):'
> >
> >
>
> That looks like a bash error message.  Syntax errors in python show up
> with a stack trace.  Run your program using the python interpreter
> like this:
>
> python file.py
> OR
> python3 file.py
>
> whatever is applicable in your environment.
>
> >
> >
> > On Thu, Sep 15, 2011 at 9:05 AM, Chris Rebert  wrote:
> >>
> >> On Wed, Sep 14, 2011 at 8:33 PM, Sagar Neve 
> wrote:
> >> > If A in B:
> >> > does nt seem to be working.
> >> > Am I missing something here.
> >>
> >> Please provide a snippet of the code in question, and be specific
> >> about how it's not working.
> >>
>
> --
> regards,
> kushal
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help regarding re.search

2011-09-14 Thread Chris Angelico
On Thu, Sep 15, 2011 at 2:55 PM, Kushal Kumaran
 wrote:
> That looks like a bash error message.  Syntax errors in python show up
> with a stack trace.  Run your program using the python interpreter
> like this:
>
> python file.py
> OR
> python3 file.py
>
> whatever is applicable in your environment.
>

Or add a shebang to the top of your script.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help regarding re.search

2011-09-14 Thread Kushal Kumaran
On Thu, Sep 15, 2011 at 10:11 AM, Sagar Neve  wrote:
> Here is the code
>
>
> url="http://xy.yz.com/us/r1000/012/Purple/b1/c6/e2/mzm.dxkjsfbl..d2.dpkg.ipa";
>
> Man_Param="/us/r1000"
> Opt_Param1="Purple"
> Opt_Param2="dpkg.ipa"
>
> if (Opt_Param2 in url):
>     print "hello."
> else:
>     print "bye."
>
> It  gives me:
>
> ./sample.py: line 9: syntax error near unexpected token `:'
> ./sample.py: line 9: `if (Opt_Param2 in url):    '
>
>

That looks like a bash error message.  Syntax errors in python show up
with a stack trace.  Run your program using the python interpreter
like this:

python file.py
OR
python3 file.py

whatever is applicable in your environment.

>
>
> On Thu, Sep 15, 2011 at 9:05 AM, Chris Rebert  wrote:
>>
>> On Wed, Sep 14, 2011 at 8:33 PM, Sagar Neve  wrote:
>> > If A in B:
>> > does nt seem to be working.
>> > Am I missing something here.
>>
>> Please provide a snippet of the code in question, and be specific
>> about how it's not working.
>>

-- 
regards,
kushal
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help regarding re.search

2011-09-14 Thread Sagar Neve
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.*?)"','\g', Man_Param)
Opt_Param1=re.sub(r'"(?P.*?)"','\g', Opt_Param1)
Opt_Param2=re.sub(r'"(?P.*?)"','\g', Opt_Param2)
Cat=re.sub(r'"(?P.*?)"','\g', 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  wrote:

> On Thu, Sep 15, 2011 at 2:41 PM, Sagar Neve  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
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help regarding re.search

2011-09-14 Thread Chris Angelico
On Thu, Sep 15, 2011 at 2:41 PM, Sagar Neve  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


Re: help regarding re.search

2011-09-14 Thread Sagar Neve
Here is the code


url="http://xy.yz.com/us/r1000/012/Purple/b1/c6/e2/mzm.dxkjsfbl..d2.dpkg.ipa
"

Man_Param="/us/r1000"
Opt_Param1="Purple"
Opt_Param2="dpkg.ipa"

if (Opt_Param2 in url):
print "hello."
else:
print "bye."

It  gives me:

./sample.py: line 9: syntax error near unexpected token `:'
./sample.py: line 9: `if (Opt_Param2 in url):'


Help.


On Thu, Sep 15, 2011 at 9:05 AM, Chris Rebert  wrote:

> On Wed, Sep 14, 2011 at 8:33 PM, Sagar Neve  wrote:
> > If A in B:
> > does nt seem to be working.
> > Am I missing something here.
>
> Please provide a snippet of the code in question, and be specific
> about how it's not working.
>
> Cheers,
> Chris
> --
> http://rebertia.com
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help regarding re.search

2011-09-14 Thread Chris Rebert
On Wed, Sep 14, 2011 at 8:33 PM, Sagar Neve  wrote:
> If A in B:
> does nt seem to be working.
> Am I missing something here.

Please provide a snippet of the code in question, and be specific
about how it's not working.

Cheers,
Chris
--
http://rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help regarding re.search

2011-09-14 Thread Sagar Neve
If A in B:
does nt seem to be working.
Am I missing something here.

-$agar
On Sep 15, 2011 7:25 AM, "Chris Rebert"  wrote:
> On Wed, Sep 14, 2011 at 6:41 PM, Sagar Neve  wrote:
>> Hi,
>> I have a small program where I want to do just a small regex operation.
>> I want to see if value of a variable 'A' is present in an another
variable
>> 'B'.  The below code works fine but as soon as the variable 'A' has some
>> string including a dot it fails.
>
> There's no need to use regexes at all! Just do:
> if A in B:
> # do something
>
>> for example say:
>> B="dpkg.ipaz
>> The code works fine  when A="dpkg"
>> however the code does not work when A="dpkg.ipa"
>
> Right, because period is a regex metacharacter. To have it treated as
> a literal character to match, escape it:
> http://docs.python.org/library/re.html#re.escape
>
> Cheers,
> Chris
> --
> http://rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help regarding re.search

2011-09-14 Thread Chris Rebert
On Wed, Sep 14, 2011 at 6:41 PM, Sagar Neve  wrote:
> Hi,
> I have a small program where I want to do just a small regex operation.
> I want to see if value of a variable 'A' is present in an another variable
> 'B'.  The below code works fine but as soon as the variable 'A' has some
> string including a dot it fails.

There's no need to use regexes at all! Just do:
if A in B:
# do something

> for example say:
> B="dpkg.ipaz
> The code works fine  when A="dpkg"
> however the code does not work when A="dpkg.ipa"

Right, because period is a regex metacharacter. To have it treated as
a literal character to match, escape it:
http://docs.python.org/library/re.html#re.escape

Cheers,
Chris
--
http://rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list