代码拉取完成,页面将自动刷新
import shapefile
from datetime import date
# 文本字段使用'C'类型创建,第三个'size'参数可以自定义为文本值的预期长度以节省空间
# w = shapefile.Writer("shapefiles")
# w.field('TEXT', 'C')
# w.field('SHORT_TEXT', 'C', size=5)
# w.field('LONG_TEXT', 'C', size=250)
# w.null()
# w.record('Hello', 'World', 'World'*50)
# w.close()
#
# r = shapefile.Reader("shapefiles")
# print(len(r))
# print(r.shapeTypeName)
# r.close()
# 日期字段使用'D'类型创建,并且可以使用日期对象,列表或YYYYMMDD格式的字符串创建
w = shapefile.Writer('shapefiles')
w.field('DATE', 'D')
w.null()
w.null()
w.null()
w.null()
w.record(date(1898, 1, 29))
w.record([1998, 1, 30])
w.record('19980131')
w.record(None)
w.close()
r = shapefile.Reader('shapefiles')
shapeRecs = r.shapeRecords()
print(shapeRecs[0].record[0])
print(shapeRecs[1].record[0])
print(shapeRecs[2].record[0])
print(shapeRecs[3].record[0])
assert r.record(0) == [date(1898,1,29)]
assert r.record(1) == [date(1998,1,30)]
assert r.record(2) == [date(1998,1,31)]
assert r.record(3) == [None]
# 可以使用关键字参数添加属性,其中关键字是字段名称
# w = shapefile.Writer('shapefiles')
# w.field('FIRST_FLD','C','40')
# w.field('SECOND_FLD','C','40')
# w.null()
# w.null()
# w.record('First', 'Line')
# w.record(FIRST_FLD='First', SECOND_FLD='Line')
# w.close()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。