Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Nitpicking in "gotchas: late binding" #241

Closed
@brandjon

Description

@brandjon

Python's closures are late binding. This means that names within closures are looked up at the time the inner function is called.

I propose this wording be changed to

Python's closures are late binding. This means that the values of variables used in closures are looked up at the time the inner function is called.

The difference is illustrated by this code.

s = 'global'def foo():    s = 'nonlocal'    def bar():        print(s)    del s    bar()foo()

Looking up the name at call time could be taken to mean that the variable to print is decided at call time. But in fact the variable (cell) is fixed at the time bar() is compiled, and it is just the value that is subject to change. In this case, the value is deleted and so NameError is raised.

(Yeah, I'm being a bit pedantic. I guess I'm really just testing out using github and the issue tracker. Nice guide. :) )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp