Got it đ â letâs go step by step and make dill clear and practical.
dill?dill is a Python library that extends the standard pickle module.
pickle can serialize (âsaveâ) Python objects into a file and later deserialize (âloadâ) them back.
But pickle has limitations: it cannot handle things like:
đ dill overcomes many of these limitations. It can serialize almost anything in Pythonâincluding entire interactive sessions.
pip install dillimport dill
x = 42
y = [1, 2, 3]
def greet(name):
return f"Hello {name}!"
# ---- Save session ----
dill.dump_session("session.pkl")
# (Restart Python...)
# ---- Load session ----
dill.load_session("session.pkl")
print(x) # 42
print(y) # [1, 2, 3]
print(greet("AI")) # Hello AI!⥠Notice: Even the function greet is restored â this wouldnât work with pickle.
dill Save?â Numbers, strings, lists, dicts (like pickle) â Functions (including lambdas and closures) â Classes, methods, and instances â Generators, iterators â Entire interactive sessions
â What it may still struggle with:
Save one object
dill.dump(obj, open("file.pkl", "wb"))Load one object
obj = dill.load(open("file.pkl", "rb"))Save entire session (all variables)
dill.dump_session("session.pkl")Load entire session
dill.load_session("session.pkl")pickle vs dill| Feature | pickle | dill |
|---|---|---|
| Save basic types | â | â |
| Save custom classes | â | â |
| Save functions | â | â |
| Save lambdas | â | â |
| Save closures | â | â |
| Save entire session | â | â |
So:
pickle is fine.dill is the tool.You can make a quick utility file session_utils.py:
import dill
def save_session(filename="session.pkl"):
dill.dump_session(filename)
def load_session(filename="session.pkl"):
dill.load_session(filename)Then in any script:
from session_utils import save_session, load_session
x = 123
save_session("my.pkl")
# Later...
load_session("my.pkl")
print(x) # 123đ Would you like me to show you how to use dill specifically for a step-by-step experiment workflow (like Jupyter Notebook, where you checkpoint after each cell), or just for a one-shot "save everything at once" style?
Sujets populaires dans ce scrapbook :
Autres scraps de "k1ito-tech"
ăăéžæă§ă đ diskcache 㯠ăăŁăčăŻă«ăăŁăă·ă„ăäżćă§ăăă©ă€ăă©ăȘ ă§ăăĄăąăȘăć§èż«ăăă«ć€§éăźăăŒăżăăăŁăă·ă„ă§ăăŸăăăăă API ăă·ăłăă«ă§ăWebăąăăȘăæ©æą°ćŠçżăźććŠçç”æăăŁăă·ă„ăȘă©ă«ăăăäœżăăăŸăă --- ă€ăłăčăăŒă« bash pip inst...
If by âMCP serverâ you mean a server implementing the Model Context Protocol (MCP) to allow LLMs / AI agents to interact with external tools/data sour...
[2508.20722] rStar2-Agent: Agentic Reasoning Technical Report URL: https://www.arxiv.org/abs/2508.20722 Captured: 2025/9/6 17:39:22 --- Computer ...
Daytona SandboxïŒéçșç°ćąăźæ°ăăȘćŻèœæ§ Daytona SandboxăšăŻ Daytona SandboxăŻăéçșè ăăŻă©ăŠăäžă§çŹæă«éçșç°ćąăæ§çŻă»ć ±æă§ăă驿°çăȘăă©ăăăă©ăŒă ă§ăăćŸæ„ăźăăŒă«ă«éçșç°ćąăźć¶çŽăćăæăăă©ăăăă§ăăąăŻă»ăčćŻèœăȘç”±äžăăăéçșäœéš...
step-by-step E2B example in Python that shows stateful execution, installing packages, uploading a file, and doing a quick SQLite queryâall inside a s...
Agentic workflow patterns integrate modular software agents with structured large language model (LLM) workflows, enabling autonomous reasoning and ac...
Envie de créer vos propres articles ?
Get Started