[Tutor] PyGreSQL tutorial difficulties redux (Long!)

Brad Chandler mbc2@netdoor.com
Fri, 30 Mar 2001 09:09:03 -0600


----- Original Message -----
From: <kromag@nsacom.net>
To: <tutor@python.org>
Sent: Thursday, March 29, 2001 11:56 PM
Subject: [Tutor] PyGreSQL tutorial difficulties redux (Long!)


> 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
>

Well, the PyGreSQL module seems to be working properly.  I'm not familiar
with the basics.py file but I think you would need to import the PyGreSQL
module (I'm assuming that's what the
_pg is) and then import the basics.py module, and then try to create the
connection.  In your example, you tried to use the basics variable before
you imported the basics.py module. Try:

import _pg, basics

cnx = basics.DB('doug','localhost')