Best way to enumerate something in python
David Stockwell
winexpert at hotmail.com
Thu May 27 13:47:55 EDT 2004
Hi Roy,
I'm just trying to bring some order to the existing code base. I've been
asked to write completely new code. When I asked the previous developers
how they did it, they admitted its all hard coded currently. So the
question I asked then was, what do you do when a column name or table name
changes? I was told, they don't. Basically if the names ever did change,
their code would break.
With my approach, since I am defining the table, I have all that placed in
one area and people can reference it. Although i switched to the enumerate
example that was previously provided because it was much easier to do.
David
-------
Cell: http://cellphone.duneram.com/index.html
Cam: http://www.duneram.com/cam/index.html
Tax: http://www.duneram.com/index.html
>From: Roy Smith <roy at panix.com>
>To: python-list at python.org
>Subject: Re: Best way to enumerate something in python
>Date: Thu, 27 May 2004 13:31:04 -0400
>
>In article <mailman.360.1085665812.6949.python-list at python.org>,
> "David Stockwell" <winexpert at hotmail.com> wrote:
>
> > FWIW this is what I'm going to do for enumerated types in python. Its
>not
> > perfect but it will make it fairly easy to get at column names so I can
> > build SQL statements on the fly and still have fairly easy to maintain
>code
> >
> > #setup stuff
> > NAME_COL, ADDRESS_COL, CITY_COL, ZIPCODE_COL, \
> > STATE_COL, COUNTRY_COL, SS_COL, CAT_COL, \
> > DATE_COL, SALARY_COL = range(10)
> >
> > mycol = {
> > NAME_COL: " NAME ", ADDRESS_COL: " ADDRESS ",
> > CITY_COL: " CITY ", ZIPCODE_COL: " ZIPCODE ",
> > STATE_COL:" STATE ", COUNTRY_COL: " COUNTRY ",
> > SS_COL: " SS ", CAT_COL: " CAT ",
> > DATE_COL: " DATE ", SALARY_COL: " SALARY " }
> > # Use these for indexing by column name
>
>I'm not sure what problem you're trying to solve here, but I suspect the
>cure is worse than the disease. This seems like a lot of error-prone
>typing, and I'm not sure what the benefit is.
>
>What happens when your SQL schema changes? You need to make multiple
>changes to the above code to handle adding or deleting a column.
>
> > print mycol[CITY_COL]
>
>How is that any better than:
>
>print "CITY"
>--
>http://mail.python.org/mailman/listinfo/python-list
_________________________________________________________________
Get 200+ ad-free, high-fidelity stations and LIVE Major League Baseball
Gameday Audio! http://radio.msn.click-url.com/go/onm00200491ave/direct/01/
More information about the Python-list
mailing list