Reputation: 947
I have code that makes a shapefile but the number of fields is dependent on certain factors. At the moment I'm testing it on input that I know produces 3 fields so have this code.
output = shapefile.Writer(shapefile.POINT)
for i in range(1,(input.fieldcount+1)):
fieldname = "field" + str(i)
output.field(fieldname,'C','40')
for i in range(len(output.item)):
output.point(input.item[i].x,input.item[i].y)
graphshp.record(input.field[0],input.field[1],input.field[2])
But I would like to change this line:
graphshp.record(input.field[0],input.field[1],input.field[2])
So it's not hard-coded.
Upvotes: 1
Views: 475
Reputation: 169284
Per the pyshp source:
You can submit either a sequence of field values or keyword arguments of field names and values.
To submit a sequence of field values you'd do:
graphshp.record( *input.field )
In case you're interested, arbitrary argument lists are covered in Python's excellent documentation.
Upvotes: 1