Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
ウィキペディアから
Python3.xの「nonlocal」キーワードを使用するのと同様の方法で外部関数変数にアクセスする必要があります。Python 2.6でそれを行う方法はありますか?(必ずしも非ローカルキーワードを使用する必要はありません)
その場合、私は常にヘルパーオブジェクトを使用します。
def outerFunction(): class Helper: val = None helper = Helper() def innerFunction(): helper.val = "some value"
これは、外部関数スコープに値を書き込む必要がある新しいスレッドを開始するときにも役立ちます。その場合、は(スレッドの関数)helperへの引数として渡されます。innerFunction
helper
innerFunction