0

I am trying to find the keyword in a file, and if found pass the line for further processing. I implemented a similar method previously. But strangely this doesnt work. i couldnt find where I am erring. It would be great to have some guidance.

My code:

def Find_Prepend_Data(Opened_File, Opened_Cpp_File):
    Prepend_Data_Keyword = '#include '
   # Find_In_Source_File_And_Write(Opened_File, Opened_Cpp_File, Prepend_Data_Keyword)
    for line in Opened_Cpp_File:
        Keyword_Matched = [True for match in Prepend_Data_Keyword if match in line]
        if True in Keyword_Matched:
            Found_Prepend_Data = Prepend_Data(Opened_File, line)
            print str(Found_Prepend_Data)
    return

def Prepend_Data(Opened_File, Prepend_Data):
    Prepend_Data_Value = "\n" + Prepend_Data
    Write_Data(Opened_File, Prepend_Data_Value)
    return Prepend_Data_Value

My previous similar post:

Similar working method

Community
  • 1
  • 1
user3652437
  • 201
  • 2
  • 8
  • Why haven't you just edited your previous question as requested? What do you mean *"this doesn't work"*? And why am I now having to ask you for the third time to [follow PEP-0008](http://legacy.python.org/dev/peps/pep-0008/)?! – jonrsharpe May 21 '14 at 16:43
  • Does Opened_File refer to a file object, a file path, or the lines in the file? Either add more context, or clearly state what issue you are facing. – sabhiram May 21 '14 at 16:44
  • I bet your mistake is at line 5: should be [True for match in Prepend_Data_Keyword if match in line], with Prepend_Data_Keyword a list of strings like ["#include "] – mguijarr May 21 '14 at 16:49
  • Hi @jonrsharpe, the function doesn't only recognize the include keyword but the whole program and prints it. Which is pretty wierd. About the PEP-0008. I wanted to install a plugin for notepad++ unfortunately I couldnt as I dont have admin password of the computer I am working upon... I tried to connect to the pip server to install pep-08 but I am not able to connect to the server. I search many forums regarding the issue nothing works. (I am using a windows system) – user3652437 May 22 '14 at 08:33
  • @sabhiram Opened_File is just a variable of opened file which was opened using open() – user3652437 May 22 '14 at 08:35
  • @mguijarr If I make it as list of strings it doesnt recognize anything nor it does it print any of the keywords – user3652437 May 22 '14 at 08:40
  • @user3652437 you don't necessarily need to *install* PEP-0008; just read it and follow it! – jonrsharpe May 22 '14 at 08:51
  • @jonrsharpe Yeah I will do it... It would be great if you could guide me in the issue I am facing here, as well as in the question which you have duplicated. I have also added added some additional details of the problem I am facing...! Thanks again !!... – user3652437 May 22 '14 at 08:56

0 Answers0