Python: Finding a negative number in a line of text from a file -
i have program polls servers current wi-fi status every minute, , saves info .txt file. output is:
*****current wifi signal strength*****: link quality=57/70 signal level=-53 dbm
the text file contains many of these lines. i'm trying accomplish is: -find signal dbm values in lines, , append them array can can other functions such sort , average. can't seem working quite right.
does know how this?
thank you!
i go through each line in file , split line @ =
, last value, split @ space, , first value yield -53
.
strengthvalues = [] f = open("input.txt", "r") filelines = f.readlines() line in filelines: linesplit = line.split('=') strengthvalues.append(linesplit[-1].split()[0]) print strengthvalues
or list comprehension:
f = open("test.txt", "r") filelines = f.readlines() strengthvalues = [line.split('=')[-1].split()[0] line in filelines] print strengthvalues
Comments
Post a Comment