Re: [sqlite] python script example
On Thu, Mar 17, 2005 at 09:47:16AM +0800, cross wind wrote: > Thanks Gehard. Finally, I am seeing the pattern on how the scripts > ought to be run. In the pysqlite2 alpha *source* releases, there's a script included to run tests. Because it's just that single file, you can download it here, directly from the Subversion repository: http://initd.org/svn/initd/pysqlite/trunk/scripts/test-pysqlite -- Gerhard signature.asc Description: Digital signature
Re: [sqlite] python script example
On Wed, Mar 16, 2005 at 06:45:23PM +0800, cross wind wrote: > [...] > ### When ran, I get the ff messages: > > C:/PYTHON23/pythonw.exe -u "Z:/devpy/test/sqlite.pyw" > Traceback (most recent call last): > File "Z:/devpy/test/sqlite.pyw", line 1, in ? > import sqlite > File "Z:\devpy\test\sqlite.pyw", line 3, in ? > cx = sqlite.connect('xyz.db') > AttributeError: 'module' object has no attribute 'connect' Don't name your test script like an existing Python module, in this case sqlite. Because then, your test script imports itself, and not the sqlite module. -- Gerhard signature.asc Description: Digital signature
Re: [sqlite] python script example
Thanks Gehard. Finally, I am seeing the pattern on how the scripts ought to be run. On Thu, 17 Mar 2005 01:59:28 +0100, Gerhard Haering <[EMAIL PROTECTED]> wrote: > On Thu, Mar 17, 2005 at 06:52:03AM +0800, cross wind wrote: > > On my other computer I tried installing > > pysqlite-2.0.alpha2.win32-py2.3.exe and rerun my test script, it also > > failed on the same error. However, when I changed the import line to: > > > > import pysqlite2.dbapi2 as sqlite > > > > The test script worked. However the following scripts in > > \Python23\Lib\site-packages\pysqlite2\test failed to run: > > > > dbapi.py > > types.py > > > > I have the ff result: > > > > M:/Python23/pythonw.exe -u > > "M:/Python23/Lib/site-packages/pysqlite2/test/dbapi.py" > > 'import site' failed; use -v for traceback > > Traceback (most recent call last): > > File "M:/Python23/Lib/site-packages/pysqlite2/test/dbapi.py", line 25, in > > ? > > import pysqlite2.dbapi2 as sqlite > > ImportError: No module named pysqlite2.dbapi2 > > > > Why oh why? > > Not much time, my girlfriend is sending me to bed :-P > > But try this instead: > > C:\tmp>c:\Python23\python.exe > Python 2.3.5 (#62, Feb 8 2005, 16:23:02) [MSC v.1200 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> from pysqlite2 import test > >>> test.test() > ... > -- > Ran 51 tests in 0.031s > > -- Gerhard > > >
Re: [sqlite] python script example
On Thu, Mar 17, 2005 at 06:52:03AM +0800, cross wind wrote: > On my other computer I tried installing > pysqlite-2.0.alpha2.win32-py2.3.exe and rerun my test script, it also > failed on the same error. However, when I changed the import line to: > > import pysqlite2.dbapi2 as sqlite > > The test script worked. However the following scripts in > \Python23\Lib\site-packages\pysqlite2\test failed to run: > > dbapi.py > types.py > > I have the ff result: > > M:/Python23/pythonw.exe -u > "M:/Python23/Lib/site-packages/pysqlite2/test/dbapi.py" > 'import site' failed; use -v for traceback > Traceback (most recent call last): > File "M:/Python23/Lib/site-packages/pysqlite2/test/dbapi.py", line 25, in ? > import pysqlite2.dbapi2 as sqlite > ImportError: No module named pysqlite2.dbapi2 > > Why oh why? Not much time, my girlfriend is sending me to bed :-P But try this instead: C:\tmp>c:\Python23\python.exe Python 2.3.5 (#62, Feb 8 2005, 16:23:02) [MSC v.1200 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from pysqlite2 import test >>> test.test() ... -- Ran 51 tests in 0.031s -- Gerhard signature.asc Description: Digital signature
Re: [sqlite] python script example
On my other computer I tried installing pysqlite-2.0.alpha2.win32-py2.3.exe and rerun my test script, it also failed on the same error. However, when I changed the import line to: import pysqlite2.dbapi2 as sqlite The test script worked. However the following scripts in \Python23\Lib\site-packages\pysqlite2\test failed to run: dbapi.py types.py I have the ff result: M:/Python23/pythonw.exe -u "M:/Python23/Lib/site-packages/pysqlite2/test/dbapi.py" 'import site' failed; use -v for traceback Traceback (most recent call last): File "M:/Python23/Lib/site-packages/pysqlite2/test/dbapi.py", line 25, in ? import pysqlite2.dbapi2 as sqlite ImportError: No module named pysqlite2.dbapi2 Why oh why? On Wed, 16 Mar 2005 22:46:38 +0800, Ng Pheng Siong <[EMAIL PROTECTED]> wrote: > On Wed, Mar 16, 2005 at 06:45:23PM +0800, cross wind wrote: > > AttributeError: 'module' object has no attribute 'connect' > > Mine's installed from source. > > $ python2.3 > Python 2.3.4 (#1, Sep 27 2004, 11:38:44) > [GCC 2.95.4 20020320 [FreeBSD]] on freebsd4 > Type "help", "copyright", "credits" or "license" for more information. > >>> import sqlite > >>> cx = sqlite.connect('/tmp/1.db') > >>> cu = cx.cursor() > >>> cu.execute('create table t1 (a,b,c)') > >>> cu.execute('insert into t1 values (1,2,3)') > >>> cx.commit() > >>> cu.execute('select * from t1') > >>> print cu.fetchall() > [('1', '2', '3')] > > > ### What seems to be wrong? I have installed: > > ### pysqlite-1.1.6.win32-py2.3.exe > > Packaging error? > > -- > Ng Pheng Siong <[EMAIL PROTECTED]> > > http://sandbox.rulemaker.net/ngps -+- M2Crypto, ZServerSSL for Zope, Blog > http://www.sqlcrypt.com -+- Database Engine with Transparent AES Encryption >
[sqlite] python script example
### I have the following python test script: import sqlite cx = sqlite.connect('xyz.db') cu = cx.cursor() cu.execute('create table t1 (a,b,c)') cu.execute('insert into t1 values (1,2,3)') cx.commit() cu.execute("select * from t1") row = cu.fetchone() print row ### When ran, I get the ff messages: C:/PYTHON23/pythonw.exe -u "Z:/devpy/test/sqlite.pyw" Traceback (most recent call last): File "Z:/devpy/test/sqlite.pyw", line 1, in ? import sqlite File "Z:\devpy\test\sqlite.pyw", line 3, in ? cx = sqlite.connect('xyz.db') AttributeError: 'module' object has no attribute 'connect' ### What seems to be wrong? I have installed: ### pysqlite-1.1.6.win32-py2.3.exe ### Thanks. This is my first attempt at python+sqlite.