[Tutor] How to generate instance names?

Alan Gauld alan.gauld at freenet.co.uk
Tue Nov 9 05:45:56 CET 2004


> > When someone asks this, the answer is almost always they they
should use
> > dictionaries.
>
> That was my original plan.  However, I am trying to cast my program
> along object-oriented lines.

What makes you think dictionaries are not OO? :-)

> I am writing a Python program to manage a SQL database.  I wish to
> represent database tables by object classes, and table rows by
> instances of classes.  Object attributes correspond to table
columns.

Thats a fairly common approach.

> arbitrary numbers of instances.  I had thought to package the
> query-objects into lists and iterate over them; each object in the
> list can be processed by invoking its methods.

Such a list would be a lot like a cursor, no?

So why not just use a cursor?

THe roblem with creating lots of new variables is that the rest of
your program won't know about them. How would your code access foo927
in advance? But if you have a single list or dictionary object that
you fill your code can just iterate over the list and find all
objects.

Much easier that way.

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld



More information about the Tutor mailing list