0

please i have a problem with the output of subprocess.check_output method , i want to extract just the numbers from its output!! this is my code and the output is the picture below :

disply = subprocess.check_output('grgsm_scanner -p36' , shell=True).splitlines()
print disply

this is the output data : image for returned data

how can i get just the numbers from for example disply[2] and disply[3]....etc in other term i want all numbers in the data of output , i want to get for example : [24 , 939.8 , 46021 ,461, 603 ,2 ,-27,......] with number format not string , Thanks in advance,

reda R
  • 73
  • 7
  • 1
    Possible duplicate of [Extract Number from String - Python](https://stackoverflow.com/questions/26825729/extract-number-from-string-python) – Maurice Meyer Oct 27 '17 at 11:11
  • It is better to just post the text in your question rather than posting *pictures* of text. Can you be more specific about what you want to extract? The value in `disply[2]` has more than a single number in iit. Do you just want a list of numbers? Do you need to preserve the tags? **Update your question** to show what you want the final values to look like. – larsks Oct 27 '17 at 11:15

1 Answers1

0

you can use re module in python

import re 
re.findall(r'\d+',display[2])
re.findall(r'\d+',display[3])

That would extract all the numeric values.

pankaj mishra
  • 2,555
  • 2
  • 17
  • 31