help with my first use of a class

Bruno Desthuilliers onurb at xiludom.gro
Fri Oct 20 05:19:47 EDT 2006


BartlebyScrivener wrote:
> Whoah. At least I got the connection. I think. Maybe I can figure more
> on my own. Any help appreciated.
> 
> Thanks
> 
> ---------
> 
> class Connection:
>     def __init__(self, aDatasource):
>         self.db = aDatasource
>         self.conn = odbc.DriverConnect(self.db)
>         self.conn.cursor()

This creates a cursor, that's immediatly discarded.

> def random_quote():
>     """
>     Counts all of the quotes in MS Access database Quotations2005.mdb.
>     Picks one quote at random and displays it using textwrap.
>     """
>     c = Connection('DSN=Quotations')
>     c.execute ("SELECT COUNT(Quote) FROM PythonQuoteQuery")

And this will raise an AttributeError, since your (mostly useless)
Connection class doesn't define an 'execute' method.

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list