Cannot find var in python : <p>At the beginning of my program, I am defining a simple object which sets the configuration for how I am going to call a service. Like so : </p>

<pre><code>document_conversion = DocumentConversionV1(
    username='xxx',
    password='xxx',
    version='2016-05-31')
</code></pre>

<p>I then want to call a service on all files in a directory. I try to do it like so, but I believe the config object cannot be found - it seems to be out of scope, I get this error: </p>

<pre><code>NameError: name 'config' is not defined
</code></pre>

<p>Here is what I have directly after the object creation : </p>

<pre><code>yourpath = 'C:\\Users\\Desktop\\working_folder\\'

for root, dirs, files in os.walk(yourpath, topdown=False):
    for name in files:
        print(os.path.join(root, name))
        config['conversion_target'] = DocumentConversionV1.ANSWER_UNITS
        with open(join(dirname(__file__), os.path.join(root, name)), 'r') as document:
         print(json.dumps(document_conversion.convert_document(document=document, config=config), indent=2))
</code></pre>

<p>I've tried defining the config object within the for loop/within the with clause, but it still seems to not work. Curiously, if I remove the for loop from the above, it does seem to work (if ran on one file, rather than a folder).</p>

<p>Any ideas what could be the problem here ?</p>

<p>Thanks</p>
