Re: [SQLObject] Importing classes from seperate files
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Brad B. <br...@bb...> - 2003-12-01 14:30:35
|
Le dimanche, 30 nov 2003, =E0 22:37 Canada/Eastern, Scott LeFevre a = =E9crit=20 : > I'm new to Python and have been frustrated by a problem specific to=20 > SQLObject.=A0 I want to It's not a problem specific to SQLObject. > create my classes in seperate files/modules and import them into the=20= > application that I'm writing.=A0 If I do this and try to use any of = the=20 > SQLObject based classes that I've created, I always end up with an=20 > AttributeError > > For example, if I try to create a new object with the new method, I'll=20= > get something like. > Traceback (most recent call last): > =A0 File "test01.py", line 13, in ? > =A0=A0=A0 r =3D ProcReport.new() > =A0 File "/usr/lib/python2.2/site-packages/SQLObject/SQLObject.py", = line=20 > 883, in new > =A0=A0=A0 inst._SO_finishCreate(id) > =A0 File "/usr/lib/python2.2/site-packages/SQLObject/SQLObject.py", = line=20 > 904, in _SO_finishCreate > =A0=A0=A0 id =3D self._connection.queryInsertID(self._table, = self._idName, > AttributeError: 'NoneType' object has no attribute 'queryInsertID' > > Now if I copy the class code in the same file as the applicate code=20 > everything works.=A0 I've tried importing my class files via 'import=20= > classfile' and 'from classfile import *' without any success. > > I realize this is a name space issue, but I thought that the 'from ...=20= > import' statement would resolve this.=A0 Can anyone shed some light on=20= > this for me?=A0 Can I have my classes in a seperate file or do I have = to=20 > put everything in a single file for SQLObject? It's not a namespace issue. python is telling you that a NoneType=20 object doesn't have a method called queryInsertID, and if you notice in=20= the error message, the object on which that method is called is=20 self._connection. In other words, your connection is a NoneType, which it obviously=20 shouldn't be. In other words, you didn't define __connection__ (or a per class=20 _connection) in your module full of SQLObject-derived classes. One of=20 the most recent posts to this list referred to precisely the same issue=20= (with precisely the same error message.) -- Brad Bollenbach BBnet.ca= |