Persisting functions typed into the shell

Chris Angelico rosuav at gmail.com
Sat Nov 12 16:15:05 EST 2022


On Sun, 13 Nov 2022 at 05:48, Stefan Ram <ram at zedat.fu-berlin.de> wrote:
>   So much for the topic of "In Python, /everything/ is an
>   object"! There seem to be first and second-class objects:
>   Shelveable and non-shelveable objects.
>

That's a bit unfair. Everything IS an object, but not all objects can
be treated the same way. Complex numbers can't be compared for
greater-than/less-than, but they are still first-class objects.

Is it acceptable to you if the reconstituted function doesn't have
source code (which will affect tracebacks and such), as long as it
behaves the same way? If so, save the __code__.co_code attribute, and
build a new function from that.

ChrisA


More information about the Python-list mailing list