I am trying to update a datastore by uploading a formatted file(contains multiple lines). Each line in the file will create a new record in google app engine datastore. I am not sure how to add multiple rows to the datastore within a for loop. I tried:
class Records(db.Model):
something = db.StringProperty()
.....
for line in lines #lines is a file contains multiple lines
record = Records(parent = PARENT_KEY)
record.something = line
record.put()
It doesn开发者_Go百科't work and the error message is BadValueError: Property something is not multi-line. I am guessing it's because the 'record' variable refer to the same instance across each iteration.
Sorry if it's a stupid question. I am pretty new to python and google app engine. Thanks in advance for your input!
for line in lines
will keep the newline characters at the end of the lines; newlines aren't allowed in a StringProperty unless it's designated as multiline.
try record.something = line.rstrip()
to remove the newlines.
You can use the bulk loader to load data from a file into the datastore. http://code.google.com/appengine/docs/python/tools/uploadingdata.html
精彩评论