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
Question Variable not defined even though it is CoderMerv 3 70 1 hour ago
Last Post: Larz60+
  optimum chess endgame with D=3 pieces doesn't give an exact moves_to_mate variable max22 1 187 Mar-21-2024, 09:31 PM
Last Post: max22
  unbounded variable akbarza 3 426 Feb-07-2024, 03:51 PM
Last Post: deanhystad
  Variable for the value element in the index function?? Learner1 8 545 Jan-20-2024, 09:20 PM
Last Post: Learner1
  Variable definitions inside loop / could be better? gugarciap 2 373 Jan-09-2024, 11:11 PM
Last Post: deanhystad
  working directory if using windows path-variable chitarup 2 680 Nov-28-2023, 11:36 PM
Last Post: chitarup
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 511 Nov-23-2023, 02:53 PM
Last Post: rob101
  How to create a variable only for use inside the scope of a while loop? Radical 10 1,523 Nov-07-2023, 09:49 AM
Last Post: buran
  Calling functions by making part of their name with variable crouzilles 4 746 Nov-02-2023, 12:25 PM
Last Post: noisefloor
  dynamic variable name declaration in OOP style project problem jacksfrustration 3 717 Oct-22-2023, 10:05 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