Best way to enumerate something in python

David Stockwell winexpert at hotmail.com
Thu May 27 09:50:05 EDT 2004


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

# demonstration on how to 'get'

print mycol[CITY_COL]


David
-------
cell phone: http://cellphone.duneram.com/index.html
Cam: http://www.duneram.com/cam/index.html
Tax: http://www.duneram.com/index.html

_________________________________________________________________
Stop worrying about overloading your inbox - get MSN Hotmail Extra Storage! 
http://join.msn.click-url.com/go/onm00200362ave/direct/01/





More information about the Python-list mailing list