function in a function accessing vars

Jorgen Bodde jorgen.maillist at gmail.com
Wed Jun 6 05:49:23 EDT 2007


Hi all,

I wanted to solve a small problem, and I have a function that is
typically meant only as a function belonging inside another function.
>From the inner function I want to access a variable from the outer
function like;

def A():
  some_var = 1
  def B():
    some_var += 1

  B()


But this does not work, the function B does not recognize the
some_var. In my mind I thought the scope would propagate to the new
function and the vars would still be accessible.

How can I go about this?

With regards
- Jorgen



More information about the Python-list mailing list