i am trying a program which has to open all text files and read the directory,i tried a program where it prints all the 'colors' from a set of text files,
but how to's?
- print the 'filename' where colors is present in the respective file and
- print the starting line and ending line of the respective file having colors........... please help in completing my program,due to my lack of knowledge i dont know how to perform
here's my code where it will open and prints the colors present in the files of a directory.
import os
path = r'C:\Python27'
data = {}
for dir_entry in os.listdir(path):
dir_entry_path = os.path.join(path, dir_entry)
if os.path.isfile(dir_entry_path):
with open(dir_entry_path, 'r') as my_file:
for line in my_file:
for part in line.split():
if "color=" in part:
print part
the output for above program is:
color=red
But i need to extend the output as
color=red
Filename :abc
Start line of file : the first thing
End line of file : the last thing
Please help in completing my program!answers would be appreciated.