tuple、list、dictなどの要素指定できるオブジェクト以外に対して、要素指定でアクセスしようとすると、”TypeError: ‘Key’ object is unsubscriptable”となるようです。下記のようなコードを実行して、このエラーを発生させてしまいました。
1 | "Key is %(key)s" % something.key() |
名前指定で文字列を置換する場合は、dictで値を渡しましょう。
1 | "Key is %(key)s" % {"key" : something.key()} |
発生したエラー
1 2 3 4 5 6 7 8 | Traceback (most recent call last): File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 515, in __call__ handler.get(*groups) File "C:\python\relation\main.py", line 137, in get printEntry(self, entry, commentDetail = True) File "C:\python\relation\main.py", line 164, in printEntry </div>""" % comment.key() TypeError: 'Key' object is unsubscriptable |