Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #92486 > unrolled thread

Error in or

Started bysubhabrata.banerji@gmail.com
First post2015-06-11 08:40 -0700
Last post2015-06-12 12:55 +0300
Articles 8 — 5 participants

Back to article view | Back to comp.lang.python


Contents

  Error in or subhabrata.banerji@gmail.com - 2015-06-11 08:40 -0700
    Re: Error in or Ian Kelly <ian.g.kelly@gmail.com> - 2015-06-11 09:49 -0600
      Re: Error in or subhabrata.banerji@gmail.com - 2015-06-11 09:39 -0700
        Re: Error in or Ian Kelly <ian.g.kelly@gmail.com> - 2015-06-11 10:47 -0600
          Re: Error in or subhabrata.banerji@gmail.com - 2015-06-11 10:21 -0700
        Re: Error in or Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-11 18:54 +0100
    Re: Error in or Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-06-12 09:41 +0000
      Re: Error in or Marko Rauhamaa <marko@pacujo.net> - 2015-06-12 12:55 +0300

#92486 — Error in or

Fromsubhabrata.banerji@gmail.com
Date2015-06-11 08:40 -0700
SubjectError in or
Message-ID<3bf5dd52-c698-4392-be2b-5c0aeefc3cd3@googlegroups.com>
Dear Group,

In the following script,

  inp1=raw_input("PRINT YOUR INPUT:")
  if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in inp1) or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*" in inp1):
  
  if write this it is working fine, but if I write 
   
  if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in inp1) or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*" in inp1) or (''' " ''' in   inp1):
  
 the portion of (''' " ''' in   inp1) is not working.

If any one of the esteemed members may kindly suggest the error I am making.

I am using Python2.7+ on Windows 7 Professional. 

Apology for any indentation error. 

Regards,
Subhabrata Banerjee. 
         

[toc] | [next] | [standalone]


#92488

FromIan Kelly <ian.g.kelly@gmail.com>
Date2015-06-11 09:49 -0600
Message-ID<mailman.402.1434037847.13271.python-list@python.org>
In reply to#92486
On Thu, Jun 11, 2015 at 9:40 AM,  <subhabrata.banerji@gmail.com> wrote:
>   if write this it is working fine, but if I write
>
>   if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in inp1) or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*" in inp1) or (''' " ''' in   inp1):
>
>  the portion of (''' " ''' in   inp1) is not working.

Not working how? I copy-pasted the line and it appears to work fine.

[toc] | [prev] | [next] | [standalone]


#92490

Fromsubhabrata.banerji@gmail.com
Date2015-06-11 09:39 -0700
Message-ID<6a171772-23a5-471d-a4e5-73f195c9055c@googlegroups.com>
In reply to#92488
On Thursday, June 11, 2015 at 9:20:59 PM UTC+5:30, Ian wrote:
> On Thu, Jun 11, 2015 at 9:40 AM,  
> >   if write this it is working fine, but if I write
> >
> >   if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in inp1) or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*" in inp1) or (''' " ''' in   inp1):
> >
> >  the portion of (''' " ''' in   inp1) is not working.
> 
> Not working how? I copy-pasted the line and it appears to work fine.

Dear Sir,
Thank you for your kind reply. Nice to know your reply, but I am trying to send you my experiment, please see my results,

>>> def input1(n):
	inp1=raw_input("PRINT YOUR QUERY:")
	if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in inp1) or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*" in inp1) or (''' " ''' in   inp1):
		print "FINE"

		
>>> input1(1)
PRINT YOUR QUERY:"Java"
>>> input1(1)
PRINT YOUR QUERY:"Obama in London"
>>> input1(1)
PRINT YOUR QUERY:Obama AND Bush
FINE
>>> input1(1)
PRINT YOUR QUERY:Obama OR Bush
FINE
>>> 

you may get better my problem. 

Regards,
Subhabrata Banerjee. 

[toc] | [prev] | [next] | [standalone]


#92491

FromIan Kelly <ian.g.kelly@gmail.com>
Date2015-06-11 10:47 -0600
Message-ID<mailman.403.1434041298.13271.python-list@python.org>
In reply to#92490
On Thu, Jun 11, 2015 at 10:39 AM,  <subhabrata.banerji@gmail.com> wrote:
> On Thursday, June 11, 2015 at 9:20:59 PM UTC+5:30, Ian wrote:
>> On Thu, Jun 11, 2015 at 9:40 AM,
>> >   if write this it is working fine, but if I write
>> >
>> >   if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in inp1) or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*" in inp1) or (''' " ''' in   inp1):
>> >
>> >  the portion of (''' " ''' in   inp1) is not working.
>>
>> Not working how? I copy-pasted the line and it appears to work fine.
>
> Dear Sir,
> Thank you for your kind reply. Nice to know your reply, but I am trying to send you my experiment, please see my results,
>
>>>> def input1(n):
>         inp1=raw_input("PRINT YOUR QUERY:")
>         if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in inp1) or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*" in inp1) or (''' " ''' in   inp1):
>                 print "FINE"
>
>
>>>> input1(1)
> PRINT YOUR QUERY:"Java"
>>>> input1(1)
> PRINT YOUR QUERY:"Obama in London"
>>>> input1(1)
> PRINT YOUR QUERY:Obama AND Bush
> FINE
>>>> input1(1)
> PRINT YOUR QUERY:Obama OR Bush
> FINE
>>>>
>
> you may get better my problem.

The substring that you're looking for has spaces around the " symbol.
The example inputs that you gave don't have spaces around the "
symbols, so they don't contain the substring.  The triple quotes are
also unnecessary, though harmless -- it's not a multiline string, and
there are no ' symbols to escape in the string. Try replacing the
substring with just this: '"'.

[toc] | [prev] | [next] | [standalone]


#92493

Fromsubhabrata.banerji@gmail.com
Date2015-06-11 10:21 -0700
Message-ID<6d09e002-974d-4823-b8bc-9a8cce12d4d6@googlegroups.com>
In reply to#92491
On Thursday, June 11, 2015 at 10:18:33 PM UTC+5:30, Ian wrote:
> On Thu, Jun 11, 2015 at 10:39 AM,   wrote:
> > On Thursday, June 11, 2015 at 9:20:59 PM UTC+5:30, Ian wrote:
> >> On Thu, Jun 11, 2015 at 9:40 AM,
> >> >   if write this it is working fine, but if I write
> >> >
> >> >   if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in inp1) or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*" in inp1) or (''' " ''' in   inp1):
> >> >
> >> >  the portion of (''' " ''' in   inp1) is not working.
> >>
> >> Not working how? I copy-pasted the line and it appears to work fine.
> >
> > Dear Sir,
> > Thank you for your kind reply. Nice to know your reply, but I am trying to send you my experiment, please see my results,
> >
> >>>> def input1(n):
> >         inp1=raw_input("PRINT YOUR QUERY:")
> >         if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in inp1) or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*" in inp1) or (''' " ''' in   inp1):
> >                 print "FINE"
> >
> >
> >>>> input1(1)
> > PRINT YOUR QUERY:"Java"
> >>>> input1(1)
> > PRINT YOUR QUERY:"Obama in London"
> >>>> input1(1)
> > PRINT YOUR QUERY:Obama AND Bush
> > FINE
> >>>> input1(1)
> > PRINT YOUR QUERY:Obama OR Bush
> > FINE
> >>>>
> >
> > you may get better my problem.
> 
> The substring that you're looking for has spaces around the " symbol.
> The example inputs that you gave don't have spaces around the "
> symbols, so they don't contain the substring.  The triple quotes are
> also unnecessary, though harmless -- it's not a multiline string, and
> there are no ' symbols to escape in the string. Try replacing the
> substring with just this: '"'.

Dear Sir,
Thank you. It seems working.
Regards,
Subhabrata Banerjee. 

[toc] | [prev] | [next] | [standalone]


#92494

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2015-06-11 18:54 +0100
Message-ID<mailman.404.1434045317.13271.python-list@python.org>
In reply to#92490
On 11/06/2015 17:39, subhabrata.banerji@gmail.com wrote:
> On Thursday, June 11, 2015 at 9:20:59 PM UTC+5:30, Ian wrote:
>> On Thu, Jun 11, 2015 at 9:40 AM,
>>>    if write this it is working fine, but if I write
>>>
>>>    if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in inp1) or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*" in inp1) or (''' " ''' in   inp1):
>>>
>>>   the portion of (''' " ''' in   inp1) is not working.
>>
>> Not working how? I copy-pasted the line and it appears to work fine.
>
> Dear Sir,
> Thank you for your kind reply. Nice to know your reply, but I am trying to send you my experiment, please see my results,
>
>>>> def input1(n):
> 	inp1=raw_input("PRINT YOUR QUERY:")
> 	if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in inp1) or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*" in inp1) or (''' " ''' in   inp1):
> 		print "FINE"
>
> 		
>>>> input1(1)
> PRINT YOUR QUERY:"Java"
>>>> input1(1)
> PRINT YOUR QUERY:"Obama in London"
>>>> input1(1)
> PRINT YOUR QUERY:Obama AND Bush
> FINE
>>>> input1(1)
> PRINT YOUR QUERY:Obama OR Bush
> FINE
>>>>
>
> you may get better my problem.
>
> Regards,
> Subhabrata Banerjee.
>

In [6]: input1(1)
PRINT YOUR QUERY:Bush ANDES Obama
FINE

In [8]: input1(1)
PRINT YOUR QUERY:Bush ORDER Obama
FINE

Do you actually want this?

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#92508

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2015-06-12 09:41 +0000
Message-ID<557aa956$0$11125$c3e8da3@news.astraweb.com>
In reply to#92486
On Thu, 11 Jun 2015 08:40:50 -0700, subhabrata.banerji wrote:

>   if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in
>   inp1) or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*"
>   in inp1) or (''' " ''' in   inp1):

This is better written as:

    if any(substr in inp1 for substr in 
           ['AND', 'OR', 'NOT', '>', '&', 'MAYBE', '(', '*', ' " ']):
        print 'FINE'


-- 
Steve

[toc] | [prev] | [next] | [standalone]


#92509

FromMarko Rauhamaa <marko@pacujo.net>
Date2015-06-12 12:55 +0300
Message-ID<87k2v91car.fsf@elektro.pacujo.net>
In reply to#92508
Steven D'Aprano <steve+comp.lang.python@pearwood.info>:

> This is better written as:
>
>     if any(substr in inp1 for substr in 
>            ['AND', 'OR', 'NOT', '>', '&', 'MAYBE', '(', '*', ' " ']):
>         print 'FINE'

Or, equivalently:

   for substr in ['AND', 'OR', 'NOT', '>', '&', 'MAYBE', '(', '*', ' " ']:
       if substr in inp1:
           print('FINE')
           break


Marko

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web