Hello,

I've managed to muddle my way through python for the last while and have finally come up with something I dont know how to deal with.

(I have included a simplified code group below that represents what m trying to do and see)

I have a main module (test6.py) which calls a configuration module (test8.py) and then a number of other modules (test7 etc) which use the data from the configuration module. (ie: configuration.output returns "excel")

when I run the code I get the following error:
C:\Python33\python.exe  C:/Users/dcrisp/Documents/Python/gui/test6.py
sql
Traceback (most recent call last):
excel
File "C:/Users/dcrisp/Documents/Python/gui/test6.py", line 10, in <module>
    mainWin = test7.MainWindow()
File "C:\Users\dcrisp\Documents\Python\gui\test7.py", line 5, in __init__
    if configuration.input.upper() == "EXCEL":
NameError: global name 'configuration' is not defined

Which is telling me that configuration isnt a global ...

Help?  please?  OKay,  an actual question.

How do I read the configuration opbject from within test7 when it is called from test6? I dont really want to call it from every module that needs it as there is meant to be some write back functionality happening to a configuration file and if I try and do that from more than one entry point I will end up writing a corrupted config back. So A single entry point for configuration would be nice..

Or am I doing it wrong?

Whats the best way of doing what I want to do.

Again, if I havent asked the right questions, please guide and I will try and provide the information you need.

Regards,
David Crisp

Three simplified files provided below.

Module 1:
test6.py
import test8
import test7

if __name__ == '__main__':
    configuration = test8.client_configuration()

    print(configuration.output)
    print(configuration.input)

    mainWin = test7.MainWindow()
    pass

Module 2:
test7.py
class MainWindow():
    def __init__(self):
        if configuration.input.upper() == "EXCEL":
            print("excel in")
        elif configuration.input.upper() == "SQL":
            print("SQL in")
        else:
            print("Inappropriate Configuration Set")


if __name__ == '__main__':
    import test8
    configuration = test8.client_configuration()
    mainWin = MainWindow()
    pass

Module 3:
test8.py
class client_configuration():
    def __init__(self):
        self.input = "excel"
        self.output = "sql"

if __name__ == '__main__':
    configuration = client_configuration()

    print(configuration.input)
    print(configuration.output)
_______________________________________________
melbourne-pug mailing list
[email protected]
https://mail.python.org/mailman/listinfo/melbourne-pug

Reply via email to