Error getting variables from files to int() in Python
<p>I'm trying to get a value from a variable inside some files, here is the code:</p>

<pre><code>path = '/opt/log/...'
word = 'somevariable'

def enumeratepaths(path=path):
    paths = []
    for dirpath, dirnames, files in os.walk(path):
        for file in files:
            fullpath = os.path.join(dirpath, file)
            paths.append(fullpath)
    return paths

def read_files(file):
    try:
        file_open = open(file, 'r')
        search = file_open.read()
        find = search.find(word)
        find_start = find + 7
        find_stop = find + 9
        result = int(search[find_start:find_stop])
        return int(result)
    finally:
        file_open.close()

def main():
    for files in enumeratepaths():
        read_files(files)

if __name__ == "__main__":
    main()
</code></pre>

<p>The problem is that some files don't have the variable inside, because some error occurred. IN this case, this script returns an error:</p>

<pre><code>    result = int(search[find_start:find_stop])
ValueError: invalid literal for int(): RE
</code></pre>

<p>I want to get these values as <code>int</code>, but I'm stuck.</p>

<p>And another question: If the file does not have that search value, how can it be that it returns things like "RE"?</p>
