1

这是这篇文章的后续。重申一下,我有一个文本文件,其中包含给定位置的元数据和测量数据。我想将此数据写入名为 ArcGIS 的空间映射软件,我必须为列表中的每个值指定ArcGIS 中定义的数据类型。例如:

type("foo") 

在 Python 中给出,但在 ArcGISstr中称为。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']

问题是:我怎么能从dtto 来dtArcGIS?我在想一个dictionary

dtDict= dict{str:'text', int:'short', float:'float'}

但这会产生语法错误。任何帮助将不胜感激,谢谢!

4

1 回答 1

1

您正在混合两种格式,只需删除dict这样的

dtDict = {str:'text', int:'short', float:'float'}

这就是你应该如何转换类型

foo = ['plot001', '01-01-2013', 'XX', '10', '12.5', '0.65', 'A']
from ast import literal_eval

dt = []
for item in foo:
    try:
        dt.append(type(literal_eval(item)))
    except:
        dt.append(str)

dtDict = {str:'text', int:'short', float:'float'}
print map(dtDict.get, dt)

输出

['text', 'text', 'text', 'short', 'float', 'float', 'text']
于 2013-12-21T11:57:58.773 回答