Ancestors

Toot

Written by Pamela Fox on 2024-12-06 at 00:38

i always cringe when I find myself reaching for "nonlocal" in python. it looks gross, it feels gross, but it works, sooo... :-/

=> More informations about this toot | More toots from pamelafox@fosstodon.org

Descendants

Written by Andrew Woods on 2024-12-06 at 01:37

@pamelafox I’m new to learning python, so i had to look it up.

Now that I think I understand the concept, I agree.

Question: Instead of using nonlocal — why not pass the value as a argument through the necessary functions? At least it’s clear about the flow of data.

=> More informations about this toot | More toots from awoodsnet@phpc.social

Written by Pamela Fox on 2024-12-06 at 05:00

@awoodsnet good q - In this case, I'm not the one calling the functions, it's a mocked function for a test. So I know when I get called, but I dont have the flexibility to alter the arguments. The other thing I could do is to make a dict and mutate a key in it, and that'd avoid the need for nonlocal.

=> More informations about this toot | More toots from pamelafox@fosstodon.org

Proxy Information
Original URL
gemini://mastogem.picasoft.net/thread/113603084147196831
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
351.93653 milliseconds
Gemini-to-HTML Time
0.457224 milliseconds

This content has been proxied by September (ba2dc).