0

関数を使用して、グローバル ディクショナリ変数から読み書きできます。

dic = { 'someKey' : 'someVal' }
def f():
    dic['newKey'] = 'newVal'
    print dic['someKey']

モジュール内のGAE Pythonで同じことをしたい

class MainPage(webapp.RequestHandler):
    def get(self):
        user = users.get_current_user()
        if not user:
            viewValues = {}
            viewValues['login'] = (users.create_login_url(self.request.path))
            self.response.out.write(template.render('view/login.html', viewValues))
        else:
            self.redirect("/")

    viewValues = {'promotion' : [
                                {'icon': 'time_ico.png',
                                 'heading': 'Instant feedback.',
                                 'detail': 'Quiz your students and get instant results!</br>No need to waste time checking answers manually.'},
                                {'icon': 'money_ico.png',
                                 'heading': 'No equipment necessary!',
                                 'detail': 'No need to spend money on special equipment.</br>Use studyWise&copy; free of charge now.'},
                                {'icon': 'cell_ico.png',
                                 'heading': 'Accessible.',
                                 'detail': 'Can be used with any smartphone or laptop, no installation required.'},
                                {'icon': 'statistics_ico.png',
                                 'heading': 'Statistics.',
                                 'detail': 'Get helpful info about your students understanding of the learning material today.'}
                             ]
              }


Traceback (most recent call last):
  File "D:\Program Files\Google\google_appengine\google\appengine\ext\webapp\_webapp25.py", line 701, in __call__
    handler.get(*groups)
  File "C:\Current Project\StudentVoice_Refactor\src\login.py", line 14, in get
    viewValues['login'] = (users.create_login_url(self.request.path))
NameError: global name 'viewValues' is not defined

なぜこうなった?ありがとう

4

1 に答える 1

0

Python で行う方法は、self.varName を呼び出すことです。

AS3/Java では、私の知る限り、memberName または this.memberName と書くことができます。

しかし、Python ではできません。memberName ではなく、self.memberName を使用する必要があります。

まあ、それで解決すると思います。:)

于 2012-06-02T11:51:39.800 に答える