I am trying to write code that can extract values from variables in a text file.
so if the file was
"bob= 1255 mike = 13"
when I specified bob as var_name
it would extract 1255
, and so on.
based my code off of this but it doesnt seem to be working
var_name = 'bob'
regexp = re.compile(r''+var_name+'.*?([0-9.-]+)')
with open("textfile") as s:
for line in s:
match = regexp.match(line)
if match:
print(match.group(1))
var_name = 'mike'
regexp = re.compile(r''+var_name+'.*?([0-9.-]+)')
with open("textfile") as s:
for line in s:
match = regexp.match(line)
if match:
print(match.group(1))