re best way to enumerate something in Python

D

David Stockwell

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/
 
M

Michael Geary

David said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top