【发布时间】:2014-01-10 04:57:50
【问题描述】:
这是this post 的后续行动。重申一下,我有一个文本文件,其中包含给定位置的元数据和测量数据。我想将此数据写入名为 ArcGIS 的空间映射软件,我必须为列表中的每个值指定数据类型在 ArcGIS 中定义。例如:
type("foo")
在 Python 中给出 str,但在 ArcGIS 中称为 text。因此,我想将列表中每个元素的数据类型转换为 ArcGIS 中的适当数据类型。像这样的:
# This is the raw data that I want to write to ArcGIS
foo= ['plot001', '01-01-2013', 'XX', '10', '12.5', '0.65', 'A']
# The appropriate datatypes in Python are:
dt= [str, str, str, int, float, float, str]
# In ArcGIS, the datatypes should be:
dtArcGIS= ['text', 'text', 'text', 'short', 'float', 'float', 'text']
问题是:我怎样才能从dt 到dtArcGIS?我在想dictionary:
dtDict= dict{str:'text', int:'short', float:'float'}
但这会产生语法错误。任何帮助将不胜感激,谢谢!
【问题讨论】:
-
去掉
dict,花括号已经把它定义为一个dict,不需要告诉Python再做一次,dtDict= {str:'text', int:'short', float:'float'} -
type('10')是str,而不是int -
感谢您指出这一点!
标签: python dictionary arcgis type-conversion arcpy