Access local variable in method?
<p>My script opens one file (a.txt) and copies it to a new file (b.txt).  If the new file exists it indexes the name (b1.txt) so I don't overwrite the existing one.  Now I want to use the latest name for the copied file (b#.txt) outside the function (method? - sorry I'm new to this).  </p>

<p>Here's a portion of my script.  I want to use the current value of newFile when i call the replaceAll method to replace some text after I copy the original file.</p>

<hr>

<pre><code>class classMain:

    def copyFile(self,origFile,newFile):
        fIn = open(origFile,'r')
        i = 0
        while os.path.exists(newFile):
            i += 1
        newFile = 'b'+str(i)+'.txt'
        fOut = open(newFile,'w')

        for line in fIn:
            fOut.writelines(line)

        fIn.close()
        fOut.close()

    def replaceAll(self,file,searchExp,replaceExp):
        for line in self.fIn(file, inplace=1):
            if searchExp in line:
                line = line.replace(searchExp,replaceExp)
            sys.stdout.write(line)
</code></pre>

<p>Thanks!</p>
