On 23 March 2018 at 10:01, Chris Angelico <ros...@gmail.com> wrote:
>     # ... except when function bodies are involved...
>     if (input("> ") as cmd):
>         def run_cmd():
>             print("Running command", cmd) # NameError
>
>     # ... but function *headers* are executed immediately
>     if (input("> ") as cmd):
>         def run_cmd(cmd=cmd): # Capture the value in the default arg
>             print("Running command", cmd) # Works

What about

    cmd = "Something else"
    if (input("> ") as cmd):
        def run_cmd():
            print("Running command", cmd) # Closes over the "outer"
cmd, not the statement-local one?

Did I get that right? I don't really like it if so (I think it's
confusing) but I guess I could live with "well, don't do that then" as
an answer. And I don't have a better interpretation.

I'm still not convinced I like the proposal, but it's a lot cleaner
than previous versions, so thanks for that. Far fewer places where I
said "hmm, I don't understand the implications".

Paul
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to