I'm trying to do, check if line in a config file contains a string ('string1') or not, and if so then print the string and a found message ('Found string1'). I need to store the found message as a variable.
The problem is exactly here (I don't have any results for print(line) and for print('Found string1'):
def get_version():
logger.info('Started')
for file in os.listdir(running_config_dir):
if file.endswith('.config'):
for line in file:
if str('string1') in line:
print(line)
print('Found string1')
else:
logger.critical('Running Configuration not found')
logger.info('Finished')
Here is my config file,
string1
string2
string3