Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
searching contents of files
#11
I have converted the first file into list as below:

>>> f=open("/var/tmp/out1","r")
>>> p=open("/var/tmp/input2","r")
>>> disk=[]
>>> for line in p:
...     line = line.strip()
...     disk.append(line)
now i want to search this list elements in file how i can do.Please help
Reply
#12
I try to read file in list and tried below code its not working.Please help.

>>> f=open("a.txt","r")
>>> p=open("b.txt","r")
>>> disk=[]
>>> for line in p:
... line = line.strip()
... disk.append(line)

for line in f.readlines():
for word in disk[0]:
if word in line:
print line
Reply
#13
Input code into python code tags...
[Image: python_tag2.png]
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  splitting file into multiple files by searching for string AlphaInc 2 922 Jul-01-2023, 10:35 PM
Last Post: Pedroski55
  Searching for specific word in text files. JellyCreeper6 1 1,752 Nov-03-2020, 01:52 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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