2012-03-11 49 views
1

我有使shapefile文件的代碼,但字段數量依賴於某些因素。目前,我正在測試它的輸入,我知道產生3個字段,所以有這個代碼。Shapefile輸出

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]) 

但我想改變這一行:

 graphshp.record(input.field[0],input.field[1],input.field[2]) 

,所以它不是硬編碼。

回答

1

the pyshp source

您可以提交或者是字段值或關鍵字參數字段名稱和值的 的序列。

要提交的字段值的順序你會做:

graphshp.record(*input.field) 

在你感興趣的情況下,任意參數列表覆蓋在Python的excellent documentation

+0

排序謝謝! – 2012-03-11 22:55:34