Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
filter out a string
#5
(Sep-14-2018, 12:27 PM)tony1812 Wrote: Thanks for the reply.
I found the second way is better, nice and succinct. And yes it ought to be the same format. Hopefully the cpu temp never reaches temp=123.4 'C :}
In the first method match.group(), some how python complains that in <module>
match.group()
AttributeError: 'NoneType' object has no attribute 'group'

Probably, occasionally you get a string with an integer temp value - changing RE to r'\d+(\.\d+)?' will solve that. (and you will be protected even against 123.4 'C Tongue )

PS I would suggest using subprocess.check_output instead of subprocess.popen.readline(). Of course, in that case RE method is preferred.
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply


Messages In This Thread
filter out a string - by tony1812 - Sep-13-2018, 11:20 PM
RE: filter out a string - by ichabod801 - Sep-14-2018, 02:22 AM
RE: filter out a string - by tony1812 - Sep-14-2018, 12:27 PM
RE: filter out a string - by volcano63 - Sep-14-2018, 04:17 PM
RE: filter out a string - by ichabod801 - Sep-14-2018, 01:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  filter just with the string word jacklee26 2 2,424 Feb-03-2020, 03:25 PM
Last Post: snippsat
  Converting query string as a condition for filter data. shah_entrance 1 1,812 Jan-14-2020, 09:22 AM
Last Post: perfringo
  I want to filter out words with one letter in a string (pig latin translator) po0te 1 2,130 Jan-08-2020, 08:02 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020