How to use a regexp here

breamoreboy at gmail.com breamoreboy at gmail.com
Mon Dec 4 05:09:51 EST 2017


On Monday, December 4, 2017 at 9:44:27 AM UTC, Cecil Westerhof wrote:
> I have a script that was running perfectly for some time. It uses:
>     array = [elem for elem in output if 'CPU_TEMP' in elem]
> 
> But because output has changed, I have to check for CPU_TEMP at the
> beginning of the line. What would be the best way to implement this?
> 
> -- 
> Cecil Westerhof
> Senior Software Engineer
> LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Use https://docs.python.org/3/library/stdtypes.html#str.startswith instead of the test for `in`.

--
Kindest regards.

Mark Lawrence.



More information about the Python-list mailing list