谷歌应用引擎上传/下载数据到NDB

时间:2012-08-16 07:48:41

标签: app-engine-ndb

我有初始的ndb来存储数据:

class Node(ndb.Model):
  name = ndb.StringProperty()
  tag_list = ndb.TextProperty(repeated=True)
  center_point = ndb.GeoPtProperty()

我想从CSV文件导入数据。请告诉我导入数据的方法!和csv文件的结构。

1 个答案:

答案 0 :(得分:0)

import csv
reader = csv.reader(open('nodes.csv', 'rb'), delimiter=',', quotechar='"')
for row in reader:
    node = Node(
        name = row[0]
        tag_list = row[1].split(",")
    )
    node.put()

nodes.csv

name1,"tag1,tag2",""
name2,"tag3,tag4",""
name3,"tag3,tag2",""

未经测试。