{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "cf13c80c",
   "metadata": {},
   "source": [
    "# 15-11 · open() возвращает объект файла\n",
    "\n",
    "Практика к разделу [«open() возвращает объект файла»](../../site/chapters/glava-15/15-11-file-object.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9eb9f81b",
   "metadata": {},
   "source": [
    "## Подготовка"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "582e4718",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-18T15:52:56.213408Z",
     "iopub.status.busy": "2026-08-18T15:52:56.213242Z",
     "iopub.status.idle": "2026-08-18T15:52:56.232254Z",
     "shell.execute_reply": "2026-08-18T15:52:56.231813Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Готово.\n"
     ]
    }
   ],
   "source": [
    "with open(\"privet2.txt\", \"w\", encoding=\"utf-8\") as f:\n",
    "    f.write(\"привет\")\n",
    "print(\"Готово.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a7875bea",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "03350434",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-18T15:52:56.233421Z",
     "iopub.status.busy": "2026-08-18T15:52:56.233310Z",
     "iopub.status.idle": "2026-08-18T15:52:56.235944Z",
     "shell.execute_reply": "2026-08-18T15:52:56.235566Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "r privet2.txt False True\n",
      "привет\n"
     ]
    }
   ],
   "source": [
    "with open(\"privet2.txt\", \"r\", encoding=\"utf-8\") as file:\n",
    "    mode_value = file.mode\n",
    "    name_value = file.name\n",
    "    closed_during = file.closed\n",
    "    content = file.read()\n",
    "closed_after = file.closed\n",
    "print(mode_value, name_value, closed_during, closed_after)\n",
    "print(content)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "26a0f107",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "Выведите тип объекта file и убедитесь, что это не строка и не список."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "eb50a59f",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-18T15:52:56.236962Z",
     "iopub.status.busy": "2026-08-18T15:52:56.236801Z",
     "iopub.status.idle": "2026-08-18T15:52:56.239111Z",
     "shell.execute_reply": "2026-08-18T15:52:56.238680Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True True\n"
     ]
    }
   ],
   "source": [
    "with open(\"privet2.txt\", \"r\", encoding=\"utf-8\") as file:\n",
    "    tip_ne_str = not isinstance(file, str)\n",
    "    tip_ne_list = not isinstance(file, list)\n",
    "print(tip_ne_str, tip_ne_list)"
   ]
  }
 ],
 "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
}
