variables - How to mine Specified from text in python? -


i have output program text like:

------------ action specified: getinfo  gathering information...  reported chip type: 2307  reported chip id: 98-de-94-93-76-50  reported firmware version: 1.08.10  ------------ 

but must save just, reported chip type: value "2307" in variable. how it's possible?

you regex

import re match = re.search('reported chip type:\s(?p<chip_type>\d+)', my_text) chiptype = int(match.group('chip_type'))       >>> print chiptype 2307 

in case though, it's simple enough use couple splits:

chiptype = int(my_text.split('reported chip type:', 1)[-1].split('\n')[0].strip()) 

Comments

Popular posts from this blog

java - Solr query version issue: Invalid version or the data in not in 'javabin' format -

Hard vs. Soft Water: What's The Difference?

The Ten Most Livable Cities In The World