{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "5944b110",
   "metadata": {},
   "source": [
    "# 15-27 · CSV: таблицы в текстовом виде\n",
    "\n",
    "Практика к разделу [«CSV»](../../site/chapters/glava-15/15-27-csv-tablitsy.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5bd18aba",
   "metadata": {},
   "source": [
    "## Рабочий пример — почему не split(\",\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1f2bd05d",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-18T15:53:09.294099Z",
     "iopub.status.busy": "2026-08-18T15:53:09.293993Z",
     "iopub.status.idle": "2026-08-18T15:53:09.320929Z",
     "shell.execute_reply": "2026-08-18T15:53:09.320392Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Anna', 'Отлично, продолжай!']\n"
     ]
    }
   ],
   "source": [
    "import csv\n",
    "import io\n",
    "\n",
    "stroka_s_zapyatoj = 'Anna,\"Отлично, продолжай!\"'\n",
    "reader = csv.reader(io.StringIO(stroka_s_zapyatoj))\n",
    "razobrannaya_stroka = next(reader)\n",
    "print(razobrannaya_stroka)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6ff731a1",
   "metadata": {},
   "source": [
    "## Задание ★★ Самостоятельная задача — writer и DictReader"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "d25496c6",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-18T15:53:09.321882Z",
     "iopub.status.busy": "2026-08-18T15:53:09.321756Z",
     "iopub.status.idle": "2026-08-18T15:53:09.325904Z",
     "shell.execute_reply": "2026-08-18T15:53:09.325340Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'name': 'Anna', 'score': '1200'}, {'name': 'Bob', 'score': '900'}]\n"
     ]
    }
   ],
   "source": [
    "rows = [{\"name\": \"Anna\", \"score\": 1200}, {\"name\": \"Bob\", \"score\": 900}]\n",
    "with open(\"rekordy2.csv\", \"w\", encoding=\"utf-8\", newline=\"\") as f:\n",
    "    writer = csv.DictWriter(f, fieldnames=[\"name\", \"score\"])\n",
    "    writer.writeheader()\n",
    "    writer.writerows(rows)\n",
    "\n",
    "with open(\"rekordy2.csv\", \"r\", encoding=\"utf-8\", newline=\"\") as f:\n",
    "    zagruzhennye = list(csv.DictReader(f))\n",
    "print(zagruzhennye)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Cartesian Python 3.14",
   "language": "python",
   "name": "cartesian-python314"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.14.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
