{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "696e6766",
   "metadata": {},
   "source": [
    "# 15-12 · Cykl życia pliku i with\n",
    "\n",
    "Praktyka do sekcji [„File and with Lifecycle”"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "42531289",
   "metadata": {},
   "source": [
    "## Sprawa robocza"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "aa323879",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-18T15:52:57.012172Z",
     "iopub.status.busy": "2026-08-18T15:52:57.012029Z",
     "iopub.status.idle": "2026-08-18T15:52:57.028484Z",
     "shell.execute_reply": "2026-08-18T15:52:57.027974Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False True\n"
     ]
    }
   ],
   "source": [
    "with open(\"cikl.txt\", \"w\", encoding=\"utf-8\") as f:\n",
    "    f.write(\"data\")\n",
    "\n",
    "with open(\"cikl.txt\", \"r\", encoding=\"utf-8\") as file:\n",
    "    closed_inside = file.closed\n",
    "closed_outside = file.closed\n",
    "print(closed_inside, closed_outside)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3d62319d",
   "metadata": {},
   "source": [
    "## Zadanie niezależne od zadania ★★\n",
    "\n",
    "Otwórz plik BEZ with, przeczytaj go i zamknij ręcznie — upewnij się, że file.closed staje się True dopiero po wyraźnym close()."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "991f9b76",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-18T15:52:57.029441Z",
     "iopub.status.busy": "2026-08-18T15:52:57.029333Z",
     "iopub.status.idle": "2026-08-18T15:52:57.031840Z",
     "shell.execute_reply": "2026-08-18T15:52:57.031363Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False True\n"
     ]
    }
   ],
   "source": [
    "file = open(\"cikl.txt\", \"r\", encoding=\"utf-8\")\n",
    "closed_before_manual_close = file.closed\n",
    "file.read()\n",
    "file.close()\n",
    "closed_after_manual_close = file.closed\n",
    "print(closed_before_manual_close, closed_after_manual_close)"
   ]
  }
 ],
 "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
}
