From: genxtech on
On Aug 8, 7:34 pm, Tim Chase <python.l...(a)tim.thechases.com> wrote:
> On 08/08/10 17:20, genxtech wrote:
>
> > if re.search(search_string, in_string) != None:
>
> While the other responses have addressed some of the big issues,
> it's also good to use
>
>    if thing_to_test is None:
>
> or
>
>    if thing_to_test is not None:
>
> instead of "== None" or "!= None".
>
> -tkc

I would like to thank all of you for your responses. I understand
what the regular expression means, and am aware of the double negative
nature of the test. I guess what I am really getting at is why the
last test returns a value of None, and even when using the syntax
suggested in this quoted solution, the code for the last test is doing
the opposite of the previous 2 tests that also returned a value of
None. I hope this makes sense and clarifies what I am trying to ask.
Thanks
From: MRAB on
genxtech wrote:
> On Aug 8, 7:34 pm, Tim Chase <python.l...(a)tim.thechases.com> wrote:
>> On 08/08/10 17:20, genxtech wrote:
>>
>>> if re.search(search_string, in_string) != None:
>> While the other responses have addressed some of the big issues,
>> it's also good to use
>>
>> if thing_to_test is None:
>>
>> or
>>
>> if thing_to_test is not None:
>>
>> instead of "== None" or "!= None".
>>
>> -tkc
>
> I would like to thank all of you for your responses. I understand
> what the regular expression means, and am aware of the double negative
> nature of the test. I guess what I am really getting at is why the
> last test returns a value of None, and even when using the syntax
> suggested in this quoted solution, the code for the last test is doing
> the opposite of the previous 2 tests that also returned a value of
> None. I hope this makes sense and clarifies what I am trying to ask.
>
It returns None because it doesn't match.

Why doesn't it match?

Because the regex wants the last character to be a 'y', but it isn't,
it's a 'a'.
From: nn on
On Aug 9, 9:18 am, genxtech <jrmy.l...(a)gmail.com> wrote:
> On Aug 8, 7:34 pm, Tim Chase <python.l...(a)tim.thechases.com> wrote:
>
>
>
> > On 08/08/10 17:20, genxtech wrote:
>
> > > if re.search(search_string, in_string) != None:
>
> > While the other responses have addressed some of the big issues,
> > it's also good to use
>
> >    if thing_to_test is None:
>
> > or
>
> >    if thing_to_test is not None:
>
> > instead of "== None" or "!= None".
>
> > -tkc
>
> I would like to thank all of you for your responses.  I understand
> what the regular expression means, and am aware of the double negative
> nature of the test.  I guess what I am really getting at is why the
> last test returns a value of None, and even when using the syntax
> suggested in this quoted solution, the code for the last test is doing
> the opposite of the previous 2 tests that also returned a value of
> None.  I hope this makes sense and clarifies what I am trying to ask.
> Thanks


First: You understand the regular expression and the double negative
but not both of them together, otherwise you would not be asking here.
The suggestion of refactoring the code is that down the road you or
somebody else doing maintenance will have to read it again. Good books
avoid confusing grammar, likewise, good programs avoid confusing
logic.

Second: the root of your problem is the mistaken believe that P=>Q
implies (not P)=>(not Q); This is not so. Let me give an example: if
you say "if it rains" then "the ground is wet" that does not imply "if
it doesn't rain" then "the ground is not wet". You could be watering
the plants for instance. Saying "if the word finishes with a consonant
and an y" then "ay, ey, iy, oy and uy are not at the end of the word"
does not imply that "if the word does not finish with a consonant and
an y" then "ay, ey, iy, oy or uy were found at the end of the word".
The word could end in x for instance.

I hope I didn't make it more confusing, otherwise other people will
probably chime in to make it clear to you.
From: genxtech on
I have it now. Had to beat my head over it a couple times. Thanks
everybody.