Access all classes in a directory, put into an array, and print them out

Alex Martelli aleaxit at yahoo.com
Wed Jul 4 04:06:34 EDT 2001


"Stephen Boulet" <spboulet at speakeasy.net> wrote in message
news:tk54ovf2o14ede at corp.supernews.com...
    ...
> Ok, how would you write this if you actually needed the index of array in
> your for loop?
>
> My (ugly looking) solution; I hope there's something better:
>
> i = 0
> for item in array:
>    process(item)
>    someFunction(i)
>    i = i + 1

# somewhere "up above", e.g. placed in __builtin__ by
# your siteconfigure.py or whatever:
indices = xrange(sys.maxint)

for index, item in zip(indices, array):
    process(item)
    someFunction(index)

See http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52233
for a bit more discussion &c (ratings and/or comments always
welcome, of course:-).


Alex






More information about the Python-list mailing list