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
  assign value of index to variable zoor29 9 180 Apr-17-2026, 09:06 PM
Last Post: deanhystad
Question [SOLVED] Recommended way to declare global variable? Winfried 1 90 Mar-19-2026, 09:30 PM
Last Post: deanhystad
  link variable to exc blocks garbage collection Astrobert 1 747 Nov-19-2025, 05:03 AM
Last Post: Gribouillis
  variable changing types for error? Azdaghost 1 2,371 Sep-15-2025, 06:45 PM
Last Post: Gribouillis
  Functions: why use a variable "display" in a UDF as a Boolean MMartin71 3 1,138 May-26-2025, 05:55 AM
Last Post: DeaD_EyE
  PYTHONHOME Variable correct setting msetzerii 0 1,958 May-25-2025, 11:48 PM
Last Post: msetzerii
  how to get variable Azdaghost 3 1,146 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 744 Mar-07-2025, 05:02 AM
Last Post: surendrasamudrala
  not able to call the variable inside the if/elif function mareeswaran 3 1,531 Feb-09-2025, 04:27 PM
Last Post: mareeswaran
  creating arbitrary local variable names Skaperen 9 2,988 Sep-07-2024, 12:12 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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