Python Forum

Full Version: How to store the value from variable into list & run a statement then put in variable
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I have 2 question regarding this code, 1st I want to put all the values into list from the variable?

Example, Im grepping multiple ip from a file.
f = os.popen('grep '+ ip[i] + ' *')
now = f.read()
print ("output: ", now)
2nd from 1 there will be 2 possible output 1 is no match and 2 will be the matched output from grep.

If theres no match then I should put a word none in the list while if there a match I need to put exist?

I think I can do it using if else but totally blind in where to start haha. Still searching for sample command.

Thanks
Your 1st question:
list_lines = now.splitlines()