Dec-15-2018, 10:59 AM
Hi,
The following code gets the wifi quality type on a raspberry pi and works with 2.7 but not with 3.0.
The error generated is
The startswith method used is correct based on the manual
so, not sure where the error is.
I appreciate some insights.
TIA
The following code gets the wifi quality type on a raspberry pi and works with 2.7 but not with 3.0.
The error generated is
Quote:Traceback (most recent call last):
File "test.py", line 9, in <module>
if line.startswith("Quality"):
TypeError: startswith first arg must be bytes or a tuple of bytes, not str
The startswith method used is correct based on the manual
str.startswith(str, beg = 0,end = len(string));
so, not sure where the error is.
I appreciate some insights.
TIA
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
from subprocess import check_output '''get wifi connection printout''' scanoutput = check_output([ "iwlist" , "wlan0" , "scan" ]) '''separate bytes''' for line in scanoutput.split(): '''filter the quality line out''' if line.startswith( "Quality" ): '''remove text from it''' level = line.split( '=' )[ 1 ] '''get the divisor''' lev0 = float (level.split( '/' )[ 0 ]) '''get the divident''' lev1 = float (level.split( '/' )[ 1 ]) '''devide and multiply by 100 to get the %''' cal = int (lev0 / lev1) * 100 print ( "{}%" . format ( str (cal))) |