Python Forum
How to store the value from variable into list & run a statement then put in variable - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to store the value from variable into list & run a statement then put in variable (/thread-16149.html)



How to store the value from variable into list & run a statement then put in variable - searching1 - Feb-16-2019

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


RE: How to store the value from variable into list & run a statement then put in variable - heiner55 - May-29-2019

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