How to use a regexp here

Rick Johnson rantingrickjohnson at gmail.com
Mon Dec 4 09:13:21 EST 2017


Cecil Westerhof wrote:
> Joel Goldstick writes:

[...]
    
> > I like Ned's clear answer, but I'm wondering why the
> > original code would fail because the substring is at the
> > start of the line, since 'in' would still be true no
> > matter where the desired string is placed.  It would be
> > useful to see some sample data of the old data, and the
> > new data

@Goldstick 

"Inclusion testing" will return false positives when the
target is part of a larger structure (aka: word). Observe:

    >>> s = "Complex is better than complicated."
    >>> "plex" in s
    True
    >>> "om" in s
    True
    >>> s.count("om")
    2
    
I'm sure you already know this, and only made the comment
because you did not have all the data, but i thought it would
be good to mention for any lurkers who may be watching.

> There is now also a line that starts with: PCH_CPU_TEMP:
> And I do not want that one.

Yes. But be aware, that while the `str.startswith(target)`
method is indeed more efficient than a more generalized
"inclusion test", if the target is not _always_ at the
beginning of the string, then your code is going to skip
right over valid match like a round stone skipping across
the surface of a glass-smooth lake. But if you are sure the
target will always be at the beginning of the string, then
it is the best choice.

> -- 
> Cecil Westerhof
> Senior Software Engineer

Perhaps it's not politically correct for me to say this, but
i've never been one who cared much about political
correctness, so i'm just going to say it...

If you really are a "_Senior_ software engineer", and that
title is not simply an ego-booster bestowed by your boss to
a one-person-dev-team in order to avoid pay raises, then i
would expect more competence from someone who holds such an
esteemed title.

And even *IF* you are only vaguely familiar with Python, and
even *IF*, you rarely use Python in your projects, i don't
think it's too much to ask of a ~~Senior~~ Software Engineer
that they possess the basic skills required to peruse the
Python documentation and decide which method is most
appropriate for the situation at hand. And if you're using
Python on a regular basis, then you should be intimately
familiar with _all_ methods of each major type. 

Granted, your question did "hint" about the possibility of
using a regexp (although, based on the data you have
provided so far, a string method will suffice), but i would
also expect a ~~Senior~~ Software Engineer to not only be
knowledgeable of regexps, but also know when they are a
strength and when they are a weakness.

Now, there are one of two ways you can take this advice:

    (1) You can take it as a personal attack; get all huffy
    about it; drop to the floor and flail your arms and legs
    like a petulant two-year-old who didn't get the toy he
    wanted; and learn nothing in the process.
        
or

    (2) You can take it as what it is -> constructive criticism;
    shower me with gratitude[1]; and become a better person and
    a better programmer in the process.
        
The choice is yours. 


[1] Well, i had to sneak something in there for myself,
after all, it is the season of giving, yes? O:-)

    Here comes santa claws...
    Here comes santa claws...
    ...




More information about the Python-list mailing list