diff --git a/file-io.ipynb b/file-io.ipynb index 5560737..23f14e2 100644 --- a/file-io.ipynb +++ b/file-io.ipynb @@ -10,7 +10,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -43,7 +43,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -55,7 +55,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -70,7 +70,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -99,7 +99,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -108,7 +108,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 24, "metadata": {}, "outputs": [], "source": [ @@ -119,20 +119,9 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 33, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "from pathlib import Path\n", "\n", @@ -146,7 +135,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -155,6 +144,66 @@ " with open(iliad_file, \"r\") as f:\n", " a.write(f.read() + \"\\n\")\n" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Homework:\n", + "------" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "iliad_full = \"\"\n", + "with open(\"pope-iliad.txt\", \"r\") as f:\n", + " iliad_full = f.read()" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [], + "source": [ + "iliad_split = iliad_full.splitlines()\n", + "\n", + "start = 0\n", + "# Start at beginning of book 1\n", + "for i, line in enumerate(iliad_split):\n", + " if \"THE CONTENTION OF ACHILLES AND AGAMEMNON\" in line:\n", + " start = i\n", + " break\n", + "\n", + "iliad_1000 = iliad_split[start:start+1000]" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [], + "source": [ + "output_dir = Path(\"iliad_1000\")\n", + "\n", + "if not output_dir.exists():\n", + " output_dir.mkdir()" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [], + "source": [ + "for i in range(len(iliad_1000)):\n", + " with open(f\"./{output_dir}/iliad_line_{i+1}.txt\", \"w\") as f:\n", + " f.write(iliad_1000[i])" + ] } ], "metadata": { diff --git a/my_files/all_lines.txt b/my_files/all_lines.txt index 4b9ed27..0366d42 100644 --- a/my_files/all_lines.txt +++ b/my_files/all_lines.txt @@ -22,3 +22,11 @@ With tame content, and thou possess’d of thine? Great as thou art, and like a god in fight, Such as a king might ask; and let it be Then thus the king: “Shall I my prize resign +At thy demand shall I restore the maid? +A treasure worthy her, and worthy me. +First let the just equivalent be paid; +Think not to rob me of a soldier’s right. +With tame content, and thou possess’d of thine? +Great as thou art, and like a god in fight, +Such as a king might ask; and let it be +Then thus the king: “Shall I my prize resign