[Tutor] Help needed with script to batch-create shapefiles
Jeff Shannon
jeffshannon at gmail.com
Thu Feb 17 01:52:19 CET 2005
On Wed, 16 Feb 2005 21:37:10 +0000, Chris Bromley
<lgxjcb at nottingham.ac.uk> wrote:
> Any help would be greatly appreciated!
Others have already pointed out that we will have a hard time helping
without a bit more information. But I've noticed something odd in
your code -- it probably doesn't have anything to do with your
problem, but it seems like an awkward idiom to me.
> fc = fcs.next()
>
> while fc:
> # [...]
> fc = fcs.next()
This, it seems to me, is equivalent to (but less readable than) the following:
. for fc in fcs:
. # [...]
If you're going to do something with every member of a list, then it's
much more straightforward to use a for loop (which automatically
tracks the iteration) than to use a while loop and manually adjusting
the loop-controlling expression.
Actually, it occurs to me that this *might* cause a confusing result
in your code. Presuming that fcs is a standard iterator (as your
usage of next() suggests), then calling next() on an exhausted
iterator will raise a StopIteration exception. The for loop will
automatically handle that, but with your while loop it would be caught
by the following bare except statement. That means that you'll run
(what I presume to be) your error-handling code even when you
successfully convert every member of fcs...
Jeff Shannon
More information about the Tutor
mailing list