LoginJoin GenScrap
Retour Ă  la galerie publique
De : k1ito-tech‱par k1ito‱2 months ago

Got it 👍 — let’s go step by step and make dill clear and practical.


#🔎 What is 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:

    • user-defined functions
    • lambdas
    • classes defined inside functions
    • some iterators, generators, closures

👉 dill overcomes many of these limitations. It can serialize almost anything in Python—including entire interactive sessions.


#🚀 How to Install

bash
pip install dill

#đŸ§Ș Basic Usage

python
import 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.


#đŸ§© What Can 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:

  • Open file handles, sockets, database connections (not serializable in principle)
  • OS-level resources (threads, processes)

#🧰 Core APIs

  1. Save one object

    python
    dill.dump(obj, open("file.pkl", "wb"))
  2. Load one object

    python
    obj = dill.load(open("file.pkl", "rb"))
  3. Save entire session (all variables)

    python
    dill.dump_session("session.pkl")
  4. Load entire session

    python
    dill.load_session("session.pkl")

#🆚 pickle vs dill

Featurepickledill
Save basic types✅✅
Save custom classes✅✅
Save functions❌✅
Save lambdas❌✅
Save closures❌✅
Save entire session❌✅

So:

  • If you just need simple data (numbers, arrays, dicts), pickle is fine.
  • If you want to checkpoint your whole working environment (like Jupyter does), dill is the tool.

#⚡ Practical Tip

You can make a quick utility file session_utils.py:

python
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:

python
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?

À propos de ce scrapbook
Voir aussi

Autres scraps de "k1ito-tech"

diskcache

ă„ă„éžæŠžă§ă™ 👍 diskcache は ディă‚čă‚Żă«ă‚­ăƒŁăƒƒă‚·ăƒ„ă‚’äżć­˜ă§ăă‚‹ăƒ©ă‚€ăƒ–ăƒ©ăƒȘ で、メヱăƒȘă‚’ćœ§èż«ă›ăšă«ć€§é‡ăźăƒ‡ăƒŒă‚żă‚’ă‚­ăƒŁăƒƒă‚·ăƒ„ă§ăăŸă™ă€‚ă—ă‹ă‚‚ API ăŒă‚·ăƒłăƒ—ăƒ«ă§ă€WebケプăƒȘă‚„æ©Ÿæą°ć­Šçż’ăźć‰ć‡Šç†ç”æžœă‚­ăƒŁăƒƒă‚·ăƒ„ăȘă©ă«ă‚‚ă‚ˆăäœżă‚ă‚ŒăŸă™ă€‚ --- ă‚€ăƒłă‚čăƒˆăƒŒăƒ« bash pip inst...

about 1 month ago‱
#python caching#diskcache+3

Best mcp server development sdk?

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...

about 1 month ago‱
#model context protocol#mcp sdk+3

# [2508.20722] rStar2-Agent: Agentic Reasoning Technical Report

[2508.20722] rStar2-Agent: Agentic Reasoning Technical Report URL: https://www.arxiv.org/abs/2508.20722 Captured: 2025/9/6 17:39:22 --- Computer ...

about 2 months ago‱
#agentic reinforcement learning#large language models+3

Daytona Sandbox開ç™șç’°ćąƒăźæ–°ăŸăȘćŻèƒœæ€§

Daytona Sandbox開ç™șç’°ćąƒăźæ–°ăŸăȘćŻèƒœæ€§ Daytona Sandboxずは Daytona Sandboxは、開ç™șè€…ăŒă‚Żăƒ©ă‚Šăƒ‰äžŠă§çžŹæ™‚ă«é–‹ç™șç’°ćąƒă‚’æ§‹çŻ‰ăƒ»ć…±æœ‰ă§ăă‚‹é©æ–°çš„ăȘăƒ—ăƒ©ăƒƒăƒˆăƒ•ă‚©ăƒŒăƒ ă§ă™ă€‚ćŸ“æ„ăźăƒ­ăƒŒă‚«ăƒ«é–‹ç™șç’°ćąƒăźćˆ¶çŽ„ă‚’ć–ă‚Šæ‰•ă„ă€ă©ă“ă‹ă‚‰ă§ă‚‚ă‚ąă‚Żă‚»ă‚čćŻèƒœăȘç”±äž€ă•ă‚ŒăŸé–‹ç™ș䜓隓...

about 2 months ago‱
#daytona#sandbox+3

E2B example in Python

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...

about 2 months ago‱
#e2b#python+3

# Agentic workflow patterns - AWS Prescriptive Guidance

Agentic workflow patterns integrate modular software agents with structured large language model (LLM) workflows, enabling autonomous reasoning and ac...

2 months ago‱
#aws#agentic ai+3

Envie de créer vos propres articles ?

Get Started