Python Forum
How to store the value from variable into list & run a statement then put in variable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to store the value from variable into list & run a statement then put in variable
#1
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
Reply
#2
Your 1st question:
list_lines = now.splitlines()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how to get variable Azdaghost 3 383 Apr-23-2025, 07:43 PM
Last Post: deanhystad
  I trying to automate the Variable Logon button using the python code but I couldn't surendrasamudrala 0 303 Mar-07-2025, 05:02 AM
Last Post: surendrasamudrala
  not able to call the variable inside the if/elif function mareeswaran 3 615 Feb-09-2025, 04:27 PM
Last Post: mareeswaran
  creating arbitrary local variable names Skaperen 9 1,893 Sep-07-2024, 12:12 AM
Last Post: Skaperen
  Variable Substitution call keys Bobbee 15 2,854 Aug-28-2024, 01:52 PM
Last Post: Bobbee
  how solve: local variable referenced before assignment ? trix 5 1,825 Jun-15-2024, 07:15 PM
Last Post: trix
  Variable being erased inside of if statement deusablutum 8 2,202 Jun-15-2024, 07:00 PM
Last Post: ndc85430
  Cant contain variable in regex robertkwild 3 1,139 Jun-12-2024, 11:50 AM
Last Post: deanhystad
  is this a valid variable name? Skaperen 6 1,774 Jun-05-2024, 10:13 PM
Last Post: Skaperen
  Help with writing monitored data to mysql upon change of one particular variable donottrackmymetadata 3 1,470 Apr-18-2024, 09:55 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020