Persisting functions typed into the shell
Weatherby,Gerard
gweatherby at uchc.edu
Sat Nov 12 14:33:20 EST 2022
Sounds like Jupyter Notebooks: https://jupyter.org
From: Python-list <python-list-bounces+gweatherby=uchc.edu at python.org> on behalf of Stefan Ram <ram at zedat.fu-berlin.de>
Date: Saturday, November 12, 2022 at 1:48 PM
To: python-list at python.org <python-list at python.org>
Subject: Persisting functions typed into the shell
*** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. ***
Many readers here know interactive Python sessions with
prompts like ">>>". But a "session" could be something else.
One could imagine that when starting a new session, one
still sees all the variables and constants defined in
preceding sessions.
I have implemented something like a "restore()" and a "save()"
call. "restore()" will restore the names from the last "save()".
"save()" will look for user-defined names (it excludes certain
standard names and certain other names from my software) and
save them using the "shelve" package from the standard library.
I you know "shelve" or have read the subject line, you can
guess what comes now:
I cannot save user-defined functions this way!
When a user types into the console:
|>>> def f():
|... print( "example" )
|...
he gives source code to shell and hopes that the shell will
cherish the memory of that function. But instead it acts as
if from now on it does not know the source code of "f"!
So, there seems to be no way now to persist this function
to a file? as if by "save( f )" or something similar?
If not the source code, then maybe some other form?
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.
--
https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!kVssvGre00pk5iMVIWUbuGXUwcZ8veRBEuSiX-VLlkRVlJoQ96fl6CZG9zQ72Hky8qqofZhhhA5qZpkneyEz4-4$<https://urldefense.com/v3/__https:/mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!kVssvGre00pk5iMVIWUbuGXUwcZ8veRBEuSiX-VLlkRVlJoQ96fl6CZG9zQ72Hky8qqofZhhhA5qZpkneyEz4-4$>
More information about the Python-list
mailing list