{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "065dda56",
   "metadata": {},
   "source": [
    "# 15-13 · Курсор файла: tell() и seek()\n",
    "\n",
    "Практика к разделу [«Курсор файла»](../../site/chapters/glava-15/15-13-kursor-fajla.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "40e4bc35",
   "metadata": {},
   "source": [
    "## Подготовка"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "527b2f59",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-18T15:52:57.775487Z",
     "iopub.status.busy": "2026-08-18T15:52:57.775346Z",
     "iopub.status.idle": "2026-08-18T15:52:57.792092Z",
     "shell.execute_reply": "2026-08-18T15:52:57.791652Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Готово.\n"
     ]
    }
   ],
   "source": [
    "with open(\"alfavit2.txt\", \"w\", encoding=\"utf-8\") as f:\n",
    "    f.write(\"ABCDE\")\n",
    "print(\"Готово.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cad7f5a0",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "52c2236a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-18T15:52:57.793047Z",
     "iopub.status.busy": "2026-08-18T15:52:57.792935Z",
     "iopub.status.idle": "2026-08-18T15:52:57.795467Z",
     "shell.execute_reply": "2026-08-18T15:52:57.795072Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AB 2 CD ABCDE\n"
     ]
    }
   ],
   "source": [
    "with open(\"alfavit2.txt\", \"r\", encoding=\"utf-8\") as f:\n",
    "    first = f.read(2)\n",
    "    pos_after_first = f.tell()\n",
    "    second = f.read(2)\n",
    "    f.seek(0)\n",
    "    reread = f.read()\n",
    "print(first, pos_after_first, second, reread)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1d549e53",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "Прочитайте файл до конца, затем прочитайте ещё раз без seek() — убедитесь, что курсор сам не возвращается."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8caa123d",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-18T15:52:57.796478Z",
     "iopub.status.busy": "2026-08-18T15:52:57.796347Z",
     "iopub.status.idle": "2026-08-18T15:52:57.798687Z",
     "shell.execute_reply": "2026-08-18T15:52:57.798345Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "with open(\"alfavit2.txt\", \"r\", encoding=\"utf-8\") as f:\n",
    "    f.read()\n",
    "    posle_konca = f.read()\n",
    "posle_konca_pusto = posle_konca == \"\"\n",
    "print(posle_konca_pusto)"
   ]
  }
 ],
 "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
}
