Pythonic infinite for loop?
ethan at stoneleaf.us
Fri Apr 15 09:56:55 EDT 2011
Chris Angelico wrote:
> for i in xrange(1,10000000): # arbitrary top, don't like this
> except KeyError:
table = dbf.from_csv("csvfile") # fields get names f0, f1, f2, ...
table.rename_field('f3', 'key') # or whatever
keywords = table.create_index(keyword_only)
# keywords is usable as an iterator
for rec in keywords:
# if you only want the first contiguous records
for i, rec in enum(keywords):
if rec.key != 'keyword%d' % enum:
Disclosure: I am the author of the dbf module.
Depending on your needs for the other fields of the csv file, this might
be an easier way to access them. Field names can also be specified when
opening the csv file, I didn't bother for this example since I don't
know what all your field names are. ;)
Hope this helps!
More information about the Python-list