-by Allen B. Downey
+Materiales, notebooks de Jupyter y versión web en español de la 3.ª edición de *Think Python: How to Think Like a Computer Scientist*, de Allen B. Downey.
-You can order print and electronic versions of *Think Python 3e* from
-[Bookshop.org](https://bookshop.org/a/98697/9781098155438) and
-[Amazon](https://www.amazon.com/_/dp/1098155432?smid=ATVPDKIKX0DER&_encoding=UTF8&tag=oreilly20-20&_encoding=UTF8&tag=greenteapre01-20&linkCode=ur2&linkId=e2a529f94920295d27ec8a06e757dc7c&camp=1789&creative=9325).
+Traducción al español por [midudev](https://midu.dev) (Miguel Ángel Durán).
-The home page for the book is at [Green Tea Press](http://thinkpython.com).
+## Enlaces
+- Página pública del libro: [libropython.es](https://libropython.es)
+- Repositorio del proyecto: [github.com/midudev/ThinkPython](https://github.com/midudev/ThinkPython)
+- Página original del libro: [Green Tea Press](http://thinkpython.com)
+- Versión impresa y electrónica en inglés: [Bookshop.org](https://bookshop.org/a/98697/9781098155438) y [Amazon](https://www.amazon.com/_/dp/1098155432?smid=ATVPDKIKX0DER&_encoding=UTF8&tag=oreilly20-20&_encoding=UTF8&tag=greenteapre01-20&linkCode=ur2&linkId=e2a529f94920295d27ec8a06e757dc7c&camp=1789&creative=9325)
+
+## Requisitos
+
+- Python 3
+- `pip`
+- Jupyter Notebook o JupyterLab, si quieres abrir los notebooks localmente
+- Jupyter Book y Playwright, si quieres construir la versión web y el PDF
+
+## Instalación
+
+Desde la raíz del repositorio, instala las herramientas necesarias:
+
+```bash
+python3 -m pip install jupyter notebook jupyterlab jupyter-book playwright
+python3 -m playwright install chromium
+```
+
+Si ya tienes Jupyter instalado, puedes instalar solo lo necesario para construir el libro:
+
+```bash
+python3 -m pip install jupyter-book playwright
+python3 -m playwright install chromium
+```
+
+## Construir el libro
+
+1. Entra en la carpeta de Jupyter Book:
+
+ ```bash
+ cd jb
+ ```
+
+2. Ejecuta el script de construcción:
+
+ ```bash
+ ./build.sh
+ ```
+
+3. Revisa los archivos generados:
+
+ - HTML: `jb/_build/html/index.html`
+ - PDF: `jb/_build/html/think-python-es.pdf`
+ - Archivos estáticos para producción: `jb/_build/html/`
+ - Carpeta lista para desplegar: `dist/`
+
+## Desplegar en Cloudflare Workers
+
+El archivo `wrangler.toml` despliega los assets estáticos desde `./dist`.
+
+1. Construye el libro:
+
+ ```bash
+ cd jb
+ ./build.sh
+ cd ..
+ ```
+
+2. Despliega con Wrangler:
+
+ ```bash
+ npx wrangler login
+ npx wrangler deploy
+ ```
+
+3. Para usar `https://libropython.es`, asigna ese dominio al Worker desde Cloudflare Dashboard, en Workers & Pages > tu Worker > Settings > Domains & Routes.
+
+## Abrir los notebooks
+
+Desde la raíz del repositorio, puedes abrir los notebooks con Jupyter Notebook:
+
+```bash
+jupyter notebook
+```
+
+También puedes usar JupyterLab:
+
+```bash
+jupyter lab
+```
+
+Después, abre desde el navegador el capítulo o notebook que quieras consultar.
+
+## Estructura del proyecto
+
+- `chapters/`: notebooks originales por capítulo.
+- `jb/`: configuración y fuentes de Jupyter Book.
+- `jb/build.sh`: script para generar la versión web y el PDF.
+- `jb/_build/html/`: salida generada para publicar el libro.
+
+## Licencia
+
+Se conserva la atribución original a Allen B. Downey. La traducción al español fue realizada por [midudev](https://midu.dev) (Miguel Ángel Durán).
+
+Esta obra está bajo una [Licencia Creative Commons Atribución-NoComercial-CompartirIgual 4.0 Internacional](https://creativecommons.org/licenses/by-nc-sa/4.0/).
diff --git a/blank/chap00.ipynb b/blank/chap00.ipynb
index 55b62c2..c733efe 100644
--- a/blank/chap00.ipynb
+++ b/blank/chap00.ipynb
@@ -5,8 +5,8 @@
"id": "1331faa1",
"metadata": {},
"source": [
- "You can order print and ebook versions of *Think Python 3e* from\n",
- "[Bookshop.org](https://bookshop.org/a/98697/9781098155438) and\n",
+ "Puedes pedir las versiones impresa y ebook de *Think Python 3e* en\n",
+ "[Bookshop.org](https://bookshop.org/a/98697/9781098155438) y\n",
"[Amazon](https://www.amazon.com/_/dp/1098155432?smid=ATVPDKIKX0DER&_encoding=UTF8&tag=oreilly20-20&_encoding=UTF8&tag=greenteapre01-20&linkCode=ur2&linkId=e2a529f94920295d27ec8a06e757dc7c&camp=1789&creative=9325)."
]
},
@@ -15,7 +15,7 @@
"id": "d9724920",
"metadata": {},
"source": [
- "# Preface\n",
+ "# Prefacio\n",
"\n"
]
},
@@ -24,21 +24,21 @@
"id": "b76f38c6",
"metadata": {},
"source": [
- "## Who Is This Book For?\n",
+ "## ¿Para quién es este libro?\n",
"\n",
- "If you want to learn to program, you have come to the right place.\n",
- "Python is one of the best programming languages for beginners -- and it is also one of the most in-demand skills.\n",
+ "Si quieres aprender a programar, has llegado al lugar adecuado.\n",
+ "Python es uno de los mejores lenguajes de programación para principiantes, y también una de las habilidades más demandadas.\n",
"\n",
- "You have also come at the right time, because learning to program now is probably easier than ever.\n",
- "With virtual assistants like ChatGPT, you don't have to learn alone.\n",
- "Throughout this book, I'll suggest ways you can use these tools to accelerate your learning.\n",
+ "También has llegado en el momento adecuado, porque aprender a programar ahora probablemente sea más fácil que nunca.\n",
+ "Con asistentes virtuales como ChatGPT, no tienes que aprender en soledad.\n",
+ "A lo largo de este libro, sugeriré formas de usar estas herramientas para acelerar tu aprendizaje.\n",
"\n",
- "This book is primarily for people who have never programmed before and people who have some experience in another programming language.\n",
- "If you have substantial experience in Python, you might find the first few chapters too slow.\n",
+ "Este libro es principalmente para personas que nunca han programado y para personas que tienen algo de experiencia en otro lenguaje de programación.\n",
+ "Si tienes bastante experiencia en Python, quizá los primeros capítulos te parezcan demasiado lentos.\n",
"\n",
- "One of the challenges of learning to program is that you have to learn *two* languages: one is the programming language itself; the other is the vocabulary we use to talk about programs.\n",
- "If you learn only the programming language, you are likely to have problems when you need to interpret an error message, read documentation, talk to another person, or use virtual assistants.\n",
- "If you have done some programming, but you have not also learned this second language, I hope you find this book helpful."
+ "Uno de los retos de aprender a programar es que tienes que aprender *dos* lenguajes: uno es el propio lenguaje de programación; el otro es el vocabulario que usamos para hablar de programas.\n",
+ "Si solo aprendes el lenguaje de programación, es probable que tengas problemas cuando necesites interpretar un mensaje de error, leer documentación, hablar con otra persona o usar asistentes virtuales.\n",
+ "Si has programado algo, pero no has aprendido también este segundo lenguaje, espero que este libro te resulte útil."
]
},
{
@@ -46,21 +46,21 @@
"id": "b4dd57bc",
"metadata": {},
"source": [
- "## Goals of the Book\n",
+ "## Objetivos del libro\n",
"\n",
- "Writing this book, I tried to be careful with the vocabulary.\n",
- "I define each term when it first appears.\n",
- "And there is a glossary that the end of each chapter that reviews the terms that were introduced.\n",
+ "Al escribir este libro, intenté tener cuidado con el vocabulario.\n",
+ "Defino cada término cuando aparece por primera vez.\n",
+ "Y al final de cada capítulo hay un glosario que repasa los términos que se han introducido.\n",
"\n",
- "I also tried to be concise.\n",
- "The less mental effort it takes to read the book, the more capacity you will have for programming.\n",
+ "También intenté ser conciso.\n",
+ "Cuanto menos esfuerzo mental requiera leer el libro, más capacidad tendrás para programar.\n",
"\n",
- "But you can't learn to program just by reading a book -- you have to practice.\n",
- "For that reason, this book includes exercises at the end of every chapter where you can practice what you have learned.\n",
+ "Pero no puedes aprender a programar solo leyendo un libro: tienes que practicar.\n",
+ "Por eso, este libro incluye ejercicios al final de cada capítulo en los que puedes practicar lo que has aprendido.\n",
"\n",
- "If you read carefully and work on exercises consistently, you will make progress.\n",
- "But I'll warn you now -- learning to program is not easy, and even for experienced programmers it can be frustrating.\n",
- "As we go, I will suggest strategies to help you write correct programs and fix incorrect ones."
+ "Si lees con atención y trabajas en los ejercicios de forma constante, avanzarás.\n",
+ "Pero te aviso desde ahora: aprender a programar no es fácil, e incluso para programadores con experiencia puede ser frustrante.\n",
+ "A medida que avancemos, sugeriré estrategias para ayudarte a escribir programas correctos y arreglar los incorrectos."
]
},
{
@@ -68,31 +68,31 @@
"id": "6516d914",
"metadata": {},
"source": [
- "## Navigating the Book\n",
+ "## Cómo navegar por el libro\n",
"\n",
- "Each chapter in this book builds on the previous ones, so you should read them in order and take time to work on the exercises before you move on.\n",
+ "Cada capítulo de este libro se basa en los anteriores, así que deberías leerlos en orden y dedicar tiempo a trabajar en los ejercicios antes de seguir adelante.\n",
"\n",
- "The first six chapters introduce basic elements like arithmetic, conditionals, and loops.\n",
- "They also introduce the most important concept in programming, functions, and a powerful way to use them, recursion.\n",
+ "Los primeros seis capítulos presentan elementos básicos como la aritmética, los condicionales y los bucles.\n",
+ "También presentan el concepto más importante de la programación, las funciones, y una forma potente de usarlas, la recursión.\n",
"\n",
- "Chapters 7 and 8 introduce strings -- which can represent letter, words, and sentences -- and algorithms for working with them.\n",
+ "Los capítulos 7 y 8 presentan strings, que pueden representar letras, palabras y frases, y algoritmos para trabajar con ellas.\n",
"\n",
- "Chapters 9 through 12 introduce Python's core data structures -- lists, dictionaries, and tuples -- which are powerful tools for writing efficient programs.\n",
- "Chapter 12 presents algorithms for analyzing text and randomly generating new text.\n",
- "Algorithms like these are at the core of large language models (LLMs), so this chapter will give you an idea of how tools like ChatGPT work.\n",
+ "Los capítulos 9 a 12 presentan las estructuras de datos principales de Python: listas, diccionarios y tuplas, que son herramientas potentes para escribir programas eficientes.\n",
+ "El capítulo 12 presenta algoritmos para analizar texto y generar texto nuevo de forma aleatoria.\n",
+ "Algoritmos como estos están en el núcleo de los modelos de lenguaje grandes (LLMs), así que este capítulo te dará una idea de cómo funcionan herramientas como ChatGPT.\n",
"\n",
- "Chapter 13 is about ways to store data in long-term storage -- files and databases.\n",
- "As an exercise, you can write a program that searches a file system and finds duplicate files.\n",
+ "El capítulo 13 trata sobre formas de almacenar datos a largo plazo: archivos y bases de datos.\n",
+ "Como ejercicio, puedes escribir un programa que busque en un sistema de archivos y encuentre archivos duplicados.\n",
"\n",
- "Chapters 14 through 17 introduce object-oriented programming (OOP), which is a way to organize programs and the data they work with.\n",
- "Many Python libraries are written in object-oriented style, so these chapters will help you understand their design -- and define your own objects.\n",
+ "Los capítulos 14 a 17 presentan la programación orientada a objetos (OOP), que es una forma de organizar programas y los datos con los que trabajan.\n",
+ "Muchas librerías de Python están escritas con estilo orientado a objetos, así que estos capítulos te ayudarán a entender su diseño y a definir tus propios objetos.\n",
"\n",
- "The goal of this book is not to cover the entire Python language.\n",
- "Rather, I focus on a subset of the language that provides the greatest capability with the fewest concepts.\n",
- "Nevertheless, Python has a lot of features you can use to solve common problems efficiently.\n",
- "Chapter 18 presents some of these features.\n",
+ "El objetivo de este libro no es cubrir todo el lenguaje Python.\n",
+ "En cambio, me centro en un subconjunto del lenguaje que ofrece la mayor capacidad con el menor número de conceptos.\n",
+ "Aun así, Python tiene muchas características que puedes usar para resolver problemas comunes de forma eficiente.\n",
+ "El capítulo 18 presenta algunas de estas características.\n",
"\n",
- "Finally, Chapter 19 presents my parting thoughts and suggestions for continuing your programming journey."
+ "Por último, el capítulo 19 presenta mis reflexiones finales y sugerencias para continuar tu camino en la programación."
]
},
{
@@ -100,38 +100,38 @@
"id": "23013838",
"metadata": {},
"source": [
- "## What's new in the third edition?\n",
+ "## ¿Qué hay de nuevo en la tercera edición?\n",
"\n",
- "The biggest changes in this edition were driven by two new technologies -- Jupyter notebooks and virtual assistants.\n",
+ "Los cambios más grandes de esta edición fueron impulsados por dos tecnologías nuevas: los Jupyter notebooks y los asistentes virtuales.\n",
"\n",
- "Each chapter of this book is a Jupyter notebook, which is a document that contains both ordinary text and code.\n",
- "For me, that makes it easier to write the code, test it, and keep it consistent with the text.\n",
- "For you, it means you can run the code, modify it, and work on the exercises, all in one place.\n",
- "Instructions for working with the notebooks are in the first chapter.\n",
+ "Cada capítulo de este libro es un Jupyter notebook, que es un documento que contiene tanto texto normal como código.\n",
+ "Para mí, eso facilita escribir el código, probarlo y mantenerlo coherente con el texto.\n",
+ "Para ti, significa que puedes ejecutar el código, modificarlo y trabajar en los ejercicios, todo en un solo lugar.\n",
+ "Las instrucciones para trabajar con los notebooks están en el primer capítulo.\n",
"\n",
- "The other big change is that I've added advice for working with virtual assistants like ChatGPT and using them to accelerate your learning.\n",
- "When the previous edition of this book was published in 2016, the predecessors of these tools were far less useful and most people were unaware of them. \n",
- "Now they are a standard tool for software engineering, and I think they will be a transformational tool for learning to program -- and learning a lot of other things, too.\n",
+ "El otro gran cambio es que he añadido consejos para trabajar con asistentes virtuales como ChatGPT y usarlos para acelerar tu aprendizaje.\n",
+ "Cuando se publicó la edición anterior de este libro en 2016, los predecesores de estas herramientas eran mucho menos útiles y la mayoría de la gente no los conocía. \n",
+ "Ahora son una herramienta estándar para la ingeniería de software, y creo que serán una herramienta transformadora para aprender a programar, y para aprender muchas otras cosas también.\n",
"\n",
- "The other changes in the book were motivated by my regrets about the second edition.\n",
+ "Los demás cambios del libro fueron motivados por mis arrepentimientos sobre la segunda edición.\n",
"\n",
- "The first is that I did not emphasize software testing.\n",
- "That was already a regrettable omission in 2016, but with the advent of virtual assistants, automated testing has become even more important.\n",
- "So this edition presents Python's most widely-used testing tools, `doctest` and `unittest`, and includes several exercises where you can practice working with them.\n",
+ "El primero es que no puse suficiente énfasis en las pruebas de software.\n",
+ "Eso ya era una omisión lamentable en 2016, pero con la llegada de los asistentes virtuales, las pruebas automatizadas se han vuelto aún más importantes.\n",
+ "Así que esta edición presenta las herramientas de testing más usadas de Python, `doctest` y `unittest`, e incluye varios ejercicios donde puedes practicar con ellas.\n",
"\n",
- "My other regret is that the exercises in the second edition were uneven -- some were more interesting than others and some were too hard.\n",
- "Moving to Jupyter notebooks helped me develop and test a more engaging and effective sequence of exercises.\n",
+ "Mi otro arrepentimiento es que los ejercicios de la segunda edición eran desiguales: algunos eran más interesantes que otros y algunos eran demasiado difíciles.\n",
+ "Pasar a Jupyter notebooks me ayudó a desarrollar y probar una secuencia de ejercicios más atractiva y eficaz.\n",
"\n",
- "In this revision, the sequence of topics is almost the same, but I rearranged a few of the chapters and compressed two short chapters into one.\n",
- "Also, I expanded the coverage of strings to include regular expressions.\n",
+ "En esta revisión, la secuencia de temas es casi la misma, pero reorganicé algunos capítulos y comprimí dos capítulos cortos en uno.\n",
+ "Además, amplié la cobertura de strings para incluir expresiones regulares.\n",
"\n",
- "A few chapters use turtle graphics.\n",
- "In previous editions, I used Python's `turtle` module, but unfortunately it doesn't work in Jupyter notebooks.\n",
- "So I replaced it with a new turtle module that should be easier to use.\n",
+ "Algunos capítulos usan turtle graphics.\n",
+ "En ediciones anteriores usé el módulo `turtle` de Python, pero por desgracia no funciona en Jupyter notebooks.\n",
+ "Así que lo reemplacé por un nuevo turtle módulo que debería ser más fácil de usar.\n",
"\n",
- "Finally, I rewrote a substantial fraction of the text, clarifying places that needed it and cutting back in places where I was not as concise as I could be.\n",
+ "Por último, reescribí una parte considerable del texto, aclarando lugares que lo necesitaban y recortando en lugares donde no fui tan conciso como podía ser.\n",
"\n",
- "I am very proud of this new edition -- I hope you like it!"
+ "Estoy muy orgulloso de esta nueva edición. ¡Espero que te guste!"
]
},
{
@@ -139,27 +139,27 @@
"id": "bfb779bb",
"metadata": {},
"source": [
- "## Getting started\n",
+ "## Primeros pasos\n",
"\n",
- "For most programming languages, including Python, there are many tools you can use to write and run programs. \n",
- "These tools are called integrated development environments (IDEs).\n",
- "In general, there are two kinds of IDEs:\n",
+ "Para la mayoría de los lenguajes de programación, incluido Python, hay muchas herramientas que puedes usar para escribir y ejecutar programas. \n",
+ "Estas herramientas se llaman entornos de desarrollo integrados (IDEs).\n",
+ "En general, hay dos tipos de IDEs:\n",
"\n",
- "* Some work with files that contain code, so they provide tools for editing and running these files.\n",
+ "* Algunos trabajan con archivos que contienen código, así que proporcionan herramientas para editar y ejecutar esos archivos.\n",
"\n",
- "* Others work primarily with notebooks, which are documents that contain text and code.\n",
+ "* Otros trabajan principalmente con notebooks, que son documentos que contienen texto y código.\n",
"\n",
- "For beginners, I recommend starting with a notebook development environment like Jupyter.\n",
+ "Para principiantes, recomiendo empezar con un entorno de desarrollo de notebooks como Jupyter.\n",
"\n",
- "The notebooks for this book are available from an online repository at
+
+Puedes pedir las versiones impresa y electrónica de *Think Python 3e* en
+[Bookshop.org](https://bookshop.org/a/98697/9781098155438) y
+[Amazon](https://www.amazon.com/_/dp/1098155432?smid=ATVPDKIKX0DER&_encoding=UTF8&tag=oreilly20-20&_encoding=UTF8&tag=greenteapre01-20&linkCode=ur2&linkId=e2a529f94920295d27ec8a06e757dc7c&camp=1789&creative=9325).
+
+[Aquí está la página principal del libro en Green Tea Press](https://greenteapress.com/wp/think-python-3rd-edition/).
+
+Descargar el libro completo en PDF
+
+## Los notebooks
+
+**Capítulo 1: Programar como una forma de pensar**
+
+* [Abrir el capítulo 1 en Colab](https://colab.research.google.com/github/midudev/ThinkPython/blob/v3/chapters/chap01.ipynb)
+
+**Capítulo 2: Variables y sentencias**
+
+* [Abrir el capítulo 2 en Colab](https://colab.research.google.com/github/midudev/ThinkPython/blob/v3/chapters/chap02.ipynb)
+
+**Capítulo 3: Funciones**
+
+* [Abrir el capítulo 3 en Colab](https://colab.research.google.com/github/midudev/ThinkPython/blob/v3/chapters/chap03.ipynb)
+
+**Capítulo 4: Funciones e interfaces**
+
+* [Abrir el capítulo 4 en Colab](https://colab.research.google.com/github/midudev/ThinkPython/blob/v3/chapters/chap04.ipynb)
+
+**Capítulo 5: Condicionales y recursión**
+
+* [Abrir el capítulo 5 en Colab](https://colab.research.google.com/github/midudev/ThinkPython/blob/v3/chapters/chap05.ipynb)
+
+**Capítulo 6: Valores de retorno**
+
+* [Abrir el capítulo 6 en Colab](https://colab.research.google.com/github/midudev/ThinkPython/blob/v3/chapters/chap06.ipynb)
+
+**Capítulo 7: Iteración y búsqueda**
+
+* [Abrir el capítulo 7 en Colab](https://colab.research.google.com/github/midudev/ThinkPython/blob/v3/chapters/chap07.ipynb)
+
+**Capítulo 8: Cadenas y expresiones regulares**
+
+* [Abrir el capítulo 8 en Colab](https://colab.research.google.com/github/midudev/ThinkPython/blob/v3/chapters/chap08.ipynb)
+
+**Capítulo 9: Listas**
+
+* [Abrir el capítulo 9 en Colab](https://colab.research.google.com/github/midudev/ThinkPython/blob/v3/chapters/chap09.ipynb)
+
+**Capítulo 10: Diccionarios**
+
+* [Abrir el capítulo 10 en Colab](https://colab.research.google.com/github/midudev/ThinkPython/blob/v3/chapters/chap10.ipynb)
+
+**Capítulo 11: Tuplas**
+
+* [Abrir el capítulo 11 en Colab](https://colab.research.google.com/github/midudev/ThinkPython/blob/v3/chapters/chap11.ipynb)
+
+**Capítulo 12: Análisis y generación de texto**
+
+* [Abrir el capítulo 12 en Colab](https://colab.research.google.com/github/midudev/ThinkPython/blob/v3/chapters/chap12.ipynb)
+
+**Capítulo 13: Archivos y bases de datos**
+
+* [Abrir el capítulo 13 en Colab](https://colab.research.google.com/github/midudev/ThinkPython/blob/v3/chapters/chap13.ipynb)
+
+**Capítulo 14: Clases y funciones**
+
+* [Abrir el capítulo 14 en Colab](https://colab.research.google.com/github/midudev/ThinkPython/blob/v3/chapters/chap14.ipynb)
+
+**Capítulo 15: Clases y métodos**
+
+* [Abrir el capítulo 15 en Colab](https://colab.research.google.com/github/midudev/ThinkPython/blob/v3/chapters/chap15.ipynb)
+
+**Capítulo 16: Clases y objetos**
+
+* [Abrir el capítulo 16 en Colab](https://colab.research.google.com/github/midudev/ThinkPython/blob/v3/chapters/chap16.ipynb)
+
+**Capítulo 17: Herencia**
+
+* [Abrir el capítulo 17 en Colab](https://colab.research.google.com/github/midudev/ThinkPython/blob/v3/chapters/chap17.ipynb)
+
+**Capítulo 18: Extras de Python**
+
+* [Abrir el capítulo 18 en Colab](https://colab.research.google.com/github/midudev/ThinkPython/blob/v3/chapters/chap18.ipynb)
+
+**Capítulo 19: Reflexiones finales**
+
+* [Abrir el capítulo 19 en Colab](https://colab.research.google.com/github/midudev/ThinkPython/blob/v3/chapters/chap19.ipynb)
+
+## Recursos para docentes
+
+Cada capítulo también tiene un notebook en blanco con el texto original y la mayor parte del código eliminado. Estos notebooks sirven para hacer ejercicios guiados donde el alumnado completa los huecos.
+
+[Aquí están los enlaces a los notebooks en blanco](blank).
diff --git a/jb/prep_notebooks.py b/jb/prep_notebooks.py
index 514949d..00e1593 100644
--- a/jb/prep_notebooks.py
+++ b/jb/prep_notebooks.py
@@ -3,13 +3,25 @@
def process_cell(cell):
- # get tags
- tags = cell['metadata'].get('tags', [])
+ tags = cell['metadata'].setdefault('tags', [])
- # add hide-cell tag to solutions
if cell['cell_type'] == 'code':
source = cell['source']
+ # Hide the setup cells that download modules and configure autoreload.
+ # In most chapters both bits live in the same cell, but in some (e.g.
+ # chap04) they are split across two consecutive cells, so we detect
+ # each pattern independently to cover both layouts.
+ is_download_cell = 'def download(url):' in source
+ is_autoreload_cell = (
+ 'import thinkpython' in source and '%autoreload' in source
+ )
+
+ if is_download_cell or is_autoreload_cell:
+ for tag in ['remove-cell', 'keep']:
+ if tag not in tags:
+ tags.append(tag)
+
# remove solutions
if source.startswith('# Solution') or 'solution' in tags:
cell['source'] = []
diff --git a/wrangler.toml b/wrangler.toml
new file mode 100644
index 0000000..340fdd3
--- /dev/null
+++ b/wrangler.toml
@@ -0,0 +1,20 @@
+name = "think-python-es"
+compatibility_date = "2026-05-19"
+
+[observability]
+enabled = false
+head_sampling_rate = 1
+
+[observability.logs]
+enabled = true
+head_sampling_rate = 1
+persist = true
+invocation_logs = true
+
+[observability.traces]
+enabled = false
+persist = true
+head_sampling_rate = 1
+
+[assets]
+directory = "./dist"