Accessing parent function's variable in a child function called in the parent using python

前端 未结 2 1265
心在旅途
心在旅途 2021-01-22 17:46

In Python 3.4, I would like to call a child function, defined outside the parent function, that still has access to the parent function\'s scope (see example below). While I ha

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-22 18:15

    You can define a function attribute like parent.test = 0 outside the function and access it in the child function using parent.test

提交回复
热议问题