473,800 Members | 2,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

re best way to enumerate something in Python

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/onm...ave/direct/01/
Jul 18 '05 #1
2 1095
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/moinmo...ionProgramming
It may give you some ideas...

--
Yermat

Jul 18 '05 #2
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
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2550
by: Daniel Pryde | last post by:
Hi everyone. I was wondering if anyone might be able to help me out here. I'm currently looking to find the quickest way to find a best fit match in a large array. My problem is that I have an array of, say, 600*400, which contains a value at each point, and I need to find the value in that array which is closest to the input value. It's basically some euclidean distances that I've calculated, and I need to be able to find the best matches...
2
1712
by: David Stockwell | last post by:
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:
5
1676
by: Pekka Niiranen | last post by:
Hi, I have Perl code looping thru lines in the file: line: while (<INFILE>) { ... $_ = do something ... if (/#START/) { # Start inner loop
1
1816
by: smichr | last post by:
I see that there is a thread of a similar topic that was posted recently ( enumerate with a start index ) but thought I would start a new thread since what I am suggesting is a little different. I posted a very similar item to python-dev, but they said to post it here. Tutor also said that if anything is to be considered as PEP worthy, it should be run through here first. So...here goes. Whenever I use enumerate, I am doing so...
8
1531
by: andrewfelch | last post by:
I write a lot of code that looks like this: for myElement, elementIndex in zip( elementList, range(len(elementList))): print "myElement ", myElement, " at index: ",elementIndex My question is, is there a better, cleaner, or easier way to get at the element in a list AND the index of a loop than this?
21
1660
by: John Salerno | last post by:
If I want to make a list of four items, e.g. L = , and then figure out if a certain element precedes another element, what would be the best way to do that? Looking at the built-in list functions, I thought I could do something like: if L.index('A') < L.index('D'): # do some stuff But I didn't know if maybe there was a preferred method for this type of
2
2448
by: eight02645999 | last post by:
hi, i am using python 2.1. Can i use the code below to simulate the enumerate() function in 2.3? If not, how to simulate in 2.1? thanks from __future__ import generators def enumerate(sequence): index = 0 for item in sequence: yield index, item
21
2337
by: James Stroud | last post by:
I think that it would be handy for enumerate to behave as such: def enumerate(itrbl, start=0, step=1): i = start for it in itrbl: yield (i, it) i += step This allows much more flexibility than in the current enumerate, tightens up code in many cases, and seems that it would break no
10
3552
by: Debajit Adhikary | last post by:
I'm writing this little Python program which will pull values from a database and generate some XHTML. I'm generating a <tablewhere I would like the alternate <tr>'s to be <tr class="Even"> and <tr class="Odd"> What is the best way to do this?
0
9690
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10251
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10033
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.