diff --git a/file-io.ipynb b/file-io.ipynb index 5560737..7a35067 100644 --- a/file-io.ipynb +++ b/file-io.ipynb @@ -10,7 +10,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -27,7 +27,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -155,6 +155,35 @@ " with open(iliad_file, \"r\") as f:\n", " a.write(f.read() + \"\\n\")\n" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from pathlib import Path\n", + "\n", + "filename = \"pope-iliad\" \n", + "\n", + "#starting to read lines after the gutenberg introductions and ending 1000 lines after\n", + "start_line = 2069\n", + "end_line = 3069\n", + "\n", + "out_dir = Path(\"ilad_1000_lines\")\n", + "\n", + "if not out_dir.exists():\n", + " out_dir.mkdir()\n", + "\n", + "#reading lines from .txt file\n", + "with open(f\"./{filename}.txt\", \"r\") as f:\n", + " lines = f.readlines()[start_line - 1 : end_line]\n", + "\n", + "for index in range(len(lines)):\n", + " with open(out_dir / f\"iliad_{index}.txt\", \"w\") as f:\n", + " f.write(lines[index])\n", + "\n" + ] } ], "metadata": {