Static variables [was Re: syntax difference]

Bart bart at 1
Sat Jun 23 22:44:00 EDT 2018


  To: Chris Angelico
From: "Bart" <bart at 1:261/38.remove-ij1-this>

  To: Chris Angelico
From: Bart <bc at freeuk.com>

On 23/06/2018 21:13, Chris Angelico wrote:
> On Sat, Jun 23, 2018 at 10:41 PM, Bart <bc at freeuk.com> wrote:

>> (At what point would that happen anyway; if you do this:

> NONE of your examples are taking copies of the function. They all are
> making REFERENCES to the same function. That is all.

This is about your notion that invocations of the same function via different
references, should maintain their own versions of the function's 'static' data.

Since these references are created via the return g statement here:

     def f():
         def g():
             ....
         return g

(say to create function references i and j like this:

     i = f()
     j = f()
)

I'm assuming that something special must be happening. Otherwise, how does f()
know which reference it's being called via?

What is different, what extra bit of information is provided when f() is
invoked via i() or j()?

--
bart

-+- BBBS/Li6 v4.10 Toy-3
 + Origin: Prism bbs (1:261/38)

--- BBBS/Li6 v4.10 Toy-3
 * Origin: Prism bbs (1:261/38)



More information about the Python-list mailing list