(Mar-27-2021, 03:54 PM)deanhystad Wrote: No. text is a string. It does not contain lines. It contains newline characters.
In the old code you wrote it to a file, read it back, and counted the number of times 'Bluetooth:' appears in the file. If the count was greater than zero, you called a function.
Can you count the number of times 'Bluetooth:' appears in a string?
If you mean some like this, it doesn't work:
count = 0 text = check_output('dmesg -T', shell = True).decode('utf-8') nlines = text.count('\n') for i in range(nlines): if text.find('Bluetooth:'): count += 1 print(count)