I want to extract the testbed name from a file. This is the line where the name is present, How could I do it in Python?
Status: aaa (image='some_image_name' on testbed='test_bed_name' archiving)
If the format is always like that, you could simply slice your way to the right place:
>>> s.split('=')[-1].split(' ')[1:-1] test_bed_name
Or, you can use regular expressions:
>>> re.findall(r"(?:.*?)testbed='(.*?)'(?:.*?)", s) test_bed_name
The above is a bit of a ham-fisted approach to regular expressions, but you can always tweak it out to make it a bit more precise.