>
> When I run the test01.py app I get the AttributeError: 'NoneType' as I
> listed in a previous post. My best guess is the __connection__ variable
> isn't available when the class is declared. I've tested this by
> inserting the following code into both files:
Yep, absolutely right. A good portion of SQLObject's work is done at
declaration time (or really, import time).
your __connection__ code isn't working because SQLObject only looks for it in
the module's namespace (in this case, in the _ProcReport file), not in current
global namespace.
several possibilities to fix this, one simple one assuming your goal is to have
one central place with __connection__ for a group of objects, is to put the
__connection__ in a separate file, and import it in the SQLObject-derived
modules:
dsn.py:
connection = MySQLConnection....
_ProcReport.py:
from dsn import connection
__connection__ = connection
(or maybe)
from dsn import connection as __connection__
And now it exists at module import time, within the _ProcReport module
namespace.
If you have a more specific thing you're trying to solve by having a separate
connection definition, let us know.
- Luke
PS, all code above is non-tested, although I do almost exactly the same thing
except use the per-class "_connection" attribute.)
|