from google.appengine.ext import db k = db.Key('agNiYXpyDAsSA2ZvbyIDYmFyDA') _app = k.app() path = [] while k is not None: path.append(k.id_or_name()) path.append(k.kind()) k = k.parent() path.reverse() print 'app=%r, path=%r' % (_app, path)
when launched in the Development Console, it produces:
app=u'baz', path=[u'foo', u'bar']
upon request. A shorter alternative is to use the to_path method of to_path instances for Key (unfortunately, mistrust)
k = db.Key('agNiYXpyDAsSA2ZvbyIDYmFyDA') _app = k.app() path = k.to_path() print 'app=%r, path=%r' % (_app, path)
with the same results. But the first, longer version depends only on documented methods.
Alex martelli
source share