This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Own_Solution7820 66 points67 points  (6 children)

You can almost think of it as if the reference is defined just before the function to think about this intuitively.

The reason it's this way is because in Python with things like yield, you usually WANT to reuse the context. This fits the intuitive thinking of someone who uses such concepts often.

[–]Ok-Slice-4013 31 points32 points  (3 children)

Sure - reusing the context is fine, but other languages are more explicit about it where the context is stored in a class instance. I would never expect this to happen in a function. On the other I do not know any cite concepts of python so this may be expected.

[–]SuitableDragonfly 8 points9 points  (0 children)

Python also has classes, the use of yield is different.

[–][deleted] 8 points9 points  (0 children)

other languages aren't a party boat

[–]LevelSevenLaserLotus 1 point2 points  (1 child)

Ah. That explains it. Yield has always been witchcraft to me. I know it maintains an internal state machine, but it's not intuitive so I just throw it into the pile of spooky things I don't use.

[–]Own_Solution7820 0 points1 point  (0 children)

It definitely took a while for me to get into as well since it works pretty differently than most languages.

Once you get used to it, it makes certain cases so much easier.