[Tutor] PyGreSQL tutorial difficulties redux (Long!)

kromag@nsacom.net kromag@nsacom.net
Thu, 29 Mar 2001 21:56:51 -0800 (PST)


I am having difficulty with the PyGreSQL tutorial modules that come with 
version3.1.

I have built a vanilla PostGres (v 7.0.3) that by all appearances is 
functioning normally. After a few false starts I got PyGres to build and 
successfully connected to postgres through my python interpreter as described 
in the README. I had great fun playing with adding and removing data, but ran 
into trouble when I attempted to write the querys out to a file through 
python. Time for the tutoral. 
 
The problem I am having is: I cannot for the life of me figure out just how 
to construct the particular database that the tutoral modules need to connect 
to. 

I have created a database called 'doug' with createdb and have attempted to 
import and start the tutorial according to the instructions:

__________________________________________________________________
MODULE BASICS.PY : BASIC POSTGRES SQL COMMANDS TUTORIAL
    
This module is designed for being imported from python prompt
    
In order to run the samples included here, first create a connection
using :                        cnx = basics.DB(...)
  
The "..." should be replaced with whatever arguments you need to open an
existing database.  Usually all you need is the name of the database and,
in fact, if it is the same as your login name, you can leave it empty.
        
then start the demo with:      basics.demo(cnx)
------------------------------------------------------------------

I am a little confused initially because when I attempt to follow the 
instructions:

------------begin python session (Warning! Long!)------------------


Python 2.0 (#2, Mar 23 2001, 19:43:00) 
[GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> import _pg
>>> cnx=basics.DB('doug','localhost')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NameError: There is no variable named 'basics'
>>> #well, that didn't work
.. 
>>> basics=_pg.connect('doug','localhost')
>>> # well, that's a good sign!
.. 
>>> #now to import the basics.py demo...
.. 
>>> import basics.py

__________________________________________________________________
MODULE BASICS.PY : BASIC POSTGRES SQL COMMANDS TUTORIAL
    
This module is designed for being imported from python prompt
    
In order to run the samples included here, first create a connection
using :                        cnx = basics.DB(...)
  
The "..." should be replaced with whatever arguments you need to open an
existing database.  Usually all you need is the name of the database and,
in fact, if it is the same as your login name, you can leave it empty.
        
then start the demo with:      basics.demo(cnx)
__________________________________________________________________

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "basics.py", line 23, in ?
    from _pg import DB
ImportError: cannot import name DB
>>> 
 
--------------- End Python Session--------------------

Okay, what am I doing wrong? It will obviously do me no good whatsoever to 
attempt "cnx=basics.DB('doug', 'localhost') since 'DB' appears not to be 
loading. (Trust me, I've tried! :-)
 
This wouldn't frustrate me much if I hadn't been able to connect with the 
usual:

---------------begin fun successful stuff-------------
Python 2.0 (#2, Mar 23 2001, 19:43:00) 
[GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> import _pg
>>> db=_pg.connect('test','localhost')
>>> db.query("select * from pork")
sausage        |eggs              |      date
---------------+------------------+----------
bob evans      |free range        |1999-06-18
tenessee pride |ground hippie meal|2001-06-12
generic        |feces fed fowl    |2000-02-19
hillbilly      |clutter cluck clan|2000-08-03
hawg flesh 2000|Foghorn Leghorn   |2033-03-14
beefy bitz     |rectum stopper    |1988-08-19
(6 rows)


>>> 
>>> db.query("insert into pork values ('spam','emu omlette','06-18-1966')")
19232
>>> db.query("select eggs from pork")
eggs              
------------------
free range        
ground hippie meal
feces fed fowl    
clutter cluck clan
Foghorn Leghorn   
rectum stopper    
emu omlette       
(7 rows)

------------------------End successful stuff---------------

This is more fun than most things, but I would really like to get a clue on 
why I can't actually make the basics.py module function. I have read all the 
way through the module, hoping for clues, but it keeps coming back to 
the 'DB' function in the _pg module itself AFAICT
 
Sorry for the long, long length, but I have been known to offer too little 
info! :-)

Thanks!

Doug