Best way to enumerate something in python

Larry Bates lbates at swamisoft.com
Wed May 26 09:54:10 EDT 2004


David,

You may have to give us more detail about what
you want to do, but here goes:

listofcolumns=('field1','field2','field3')
for column in listofcolumns:
    <do something>

Most of the time I find that putting the names
in a dictionary with the column name as key and
offset as the value seems to work better.

dictofcolumns={'field1':1, 'field2': 2, 'field3':3}

value_for_field3=row[dictofcolumns['field3']]

For your second question I think you should
take a look at os.path.getatime, .gmtime, getsize
they are easier to use.

Larry Bates
Syscon, Inc.


"David Stockwell" <winexpert at hotmail.com> wrote in message
news:mailman.311.1085575108.6949.python-list at python.org...
> Hi Everyone,
>
> I'm wondering about the best way to enumerate something.
>
> I have a list of columnames for a db and I decided to put them in a giant
> tuple list for two reasons:
>    1) its unchangeable
>    2) I was hoping that creating an enumeration of those names would be
easy
>
> In the os.stat there is aparrently a list of things you can refer to eg:
> ST_SIZE, ST_ATIME, etc.
>
> How are these defined?  They appear to be related to 0,1,2,3,....   some
> sort of enumeration.
>
> I would like to create an enumeration with 'friendly names' that map to
the
> particular offset in my column name tuple.
>
> Thanks,
>
>
>
> David
> -------
> Cell: http://cellphone.duneram.com/index.html
> Cam: http://www.duneram.com/cam/index.html
> Tax: http://www.duneram.com/index.html
>
> _________________________________________________________________
> FREE pop-up blocking with the new MSN Toolbar – get it now!
> http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/
>
>





More information about the Python-list mailing list