re best way to enumerate something in Python

Discussion in 'Python' started by David Stockwell, May 26, 2004.

  1. I'm going to try using the range function.

    as in:

    ID_COL, ANIMAL_COL, HOUSING_COL = range(3)

    This appears to assign assign those vars as 'constants' with values of 0,1,2


    David Stockwell
    -------
    Cell: 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/
     
    David Stockwell, May 26, 2004
    #1
    1. Advertising

  2. David Stockwell

    Yermat Guest

    David Stockwell wrote:
    > I'm going to try using the range function.
    >
    > as in:
    >
    > ID_COL, ANIMAL_COL, HOUSING_COL = range(3)
    >
    > This appears to assign assign those vars as 'constants' with values of
    > 0,1,2


    You should get an eye on
    http://www.python.org/cgi-bin/moinmoin/EnumerationProgramming
    It may give you some ideas...

    --
    Yermat
     
    Yermat, May 26, 2004
    #2
    1. Advertising

  3. David Stockwell wrote:
    > I'm going to try using the range function.
    >
    > as in:
    >
    > ID_COL, ANIMAL_COL, HOUSING_COL = range(3)
    >
    > This appears to assign assign those vars as 'constants' with values of

    0,1,2

    Yes, this is exactly the same as if you'd written:

    ID_COL = 0
    ANIMAL_COL = 1
    HOUSING_COL = 2

    Earlier in the thread you asked:

    > 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.


    It's easy to answer a question like that by searching the Python
    installation directory (at least if the names are defined in Python source
    code, not C code). You can either do a search, or since these are defined in
    the stat module (not os.stat), you can look in stat.py, where you'll find:

    # Indices for stat struct members in tuple returned by os.stat()

    ST_MODE = 0
    ST_INO = 1
    ST_DEV = 2
    ST_NLINK = 3
    ST_UID = 4
    ST_GID = 5
    ST_SIZE = 6
    ST_ATIME = 7
    ST_MTIME = 8
    ST_CTIME = 9

    -Mike
     
    Michael Geary, May 26, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Stockwell

    Best way to enumerate something in python

    David Stockwell, May 26, 2004, in forum: Python
    Replies:
    2
    Views:
    323
    Hallvard B Furuseth
    May 26, 2004
  2. David Stockwell

    Re: Best way to enumerate something in python

    David Stockwell, May 26, 2004, in forum: Python
    Replies:
    1
    Views:
    350
  3. David Stockwell

    Re: Best way to enumerate something in python

    David Stockwell, May 27, 2004, in forum: Python
    Replies:
    3
    Views:
    374
    Roy Smith
    May 27, 2004
  4. Дамјан ГеоргиевÑки

    Best way to enumerate classes in a module

    Дамјан ГеоргиевÑки, Jun 24, 2009, in forum: Python
    Replies:
    5
    Views:
    315
    Michele Simionato
    Jun 26, 2009
  5. Robert K.

    ruby way to enumerate users

    Robert K., Feb 1, 2004, in forum: Ruby
    Replies:
    9
    Views:
    215
    Rove Monteux
    Feb 2, 2004
Loading...

Share This Page