user5095342
user5095342

Reputation:

Python module config not cooperating

So I'm trying to import some variable settings into my python script, as such, it currently fetches a file (config.py) from an FTP and puts it an usb stick. No issues here, however, when I try to import the config to it thells me:

NameError: global name 'config' is not defined

A simple python script with:

import config

print config.status

yields perfect result, but this snippit won't:

def check_status():
        os.chdir(usb_folder)
        import config
        if config.status == "active":
                print "unitstatus set to active"
                return True

Can anyone put me on the right idea/track?

Upvotes: 0

Views: 1291

Answers (1)

shahvishal
shahvishal

Reputation: 171

In order to import the config file from another folder, you would need to add that folder to your path. You can do it programmatically using sys.path.append():

import sys
sys.path.append(usb_folder)
import config

def check_status():
    if config.status == "active":
        print "unitstatus set to active"
        return True

Upvotes: 0

Related Questions