Writing a source file name to an external file
<p>I'm Python beginner. </p>

<p>I have a scenario of having to read certain url's from an entire site directories and sub-directories. 
My task now is to have a script that will go through all the .html and .php files and search for the URLs, then write the URL if its found to an external file as well as a path to the source file, ie the file where the URL was found respectively. At the moment I am testing the logic with just a .txt file and one source file.</p>

<p>Below is what I have tried. I have searched tutorials for reading from and writing to external files but havent come across for one that can allow me to write out the source file as well. </p>

<p>Any kind of help will be appreciated, thank you in advance. </p>

<p>Here is the code:</p>

<pre><code>def toFile():
    file = open('data.txt', 'w')
    file.write(line)
    print sourceFile

def readFile():
    #make the sourceFile glabal accessible
    global sourceFile 
    with open('file1.txt', 'r') as sourceFile:
         for string in sourceFile:
             if line in sourceFile:
                 print "file being written"
                 toFile()

line = raw_input ("Enter the string here")
readFile()
</code></pre>
