# This is an auto-generated Django model module created by ogrinspect.
from django.contrib.gis.db import models
class Parking(models.Model):
name = models.CharField(max_length=80)
descriptio = models.CharField(max_length=80)
geom = models.PointField(srid=4326)
objects = models.GeoManager()
# Auto-generated `LayerMapping` dictionary for Parking model
parking_mapping = {
'name' : 'Name',
'descriptio' : 'Descriptio',
'geom' : 'POINT25D',
}
parking_mapping是这里整个字符串中的dict。整个输出存储在文本字段中。如何解析文本文件,将parking_mapping解压缩为名为parking_mapping的dict。 ?
答案 0 :(得分:0)
使用json模块
mydict = {'name' : 'foo'}
with open('dump.json', 'w') as f:
json_str = json.dumps(mydict) // save json_str in database
f.write(json_str)
contents = None
with open('dump.json') as f:
json_str = json.loads(f.read())
contents = json_str
您可以浏览内容并查找词典。
答案 1 :(得分:0)
如果您可以控制文件,为什么不将它命名为.py,并将其命名为path,并导入parking_mapping?
from <file> import parking_mapping