Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
106 changes: 83 additions & 23 deletions file-io.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 11,
"metadata": {},
"outputs": [
{
Expand All @@ -27,7 +27,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -43,7 +43,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -55,7 +55,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -70,7 +70,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 15,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -99,16 +99,35 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 16,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"['Then thus the king: “Shall I my prize resign',\n",
" 'With tame content, and thou possess’d of thine?',\n",
" 'Great as thou art, and like a god in fight,',\n",
" 'Think not to rob me of a soldier’s right.',\n",
" 'At thy demand shall I restore the maid?',\n",
" 'First let the just equivalent be paid;',\n",
" 'Such as a king might ask; and let it be',\n",
" 'A treasure worthy her, and worthy me.']"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"iliad_lines = iliad_1.splitlines()"
"iliad_lines = iliad_1.splitlines()\n",
"iliad_lines"
]
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -119,20 +138,9 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<generator object Path.glob at 0x71ead4273450>"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"from pathlib import Path\n",
"\n",
Expand All @@ -146,7 +154,7 @@
},
{
"cell_type": "code",
"execution_count": 50,
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -155,6 +163,58 @@
" with open(iliad_file, \"r\") as f:\n",
" a.write(f.read() + \"\\n\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Finishing up the lab"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"# open pope-iliad to read\n",
"filename = \"pope-iliad\"\n",
"\n",
"with open(f\"./{filename}.txt\", \"r\") as f:\n",
" text = f.read()\n",
"\n",
"# split and slice lines\n",
"lines = text.splitlines()\n",
"sliced_lines = lines[1:1001]"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
"# create output directory to store files \n",
"from pathlib import Path\n",
"\n",
"out_dir = Path(\"sliced_lines\")\n",
"\n",
"if not out_dir.exists():\n",
" out_dir.mkdir()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# write each line into a file inside the sliced_lines directory\n",
"for index in range(len(sliced_lines)):\n",
" file_path = out_dir / f\"pope-iliad_{index}.txt\"\n",
" with open(file_path, \"w\") as f:\n",
" f.write(sliced_lines[index])"
]
}
],
"metadata": {
Expand Down
16 changes: 16 additions & 0 deletions my_files/all_lines.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,19 @@ 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
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
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This ebook is for the use of anyone anywhere in the United States and
Empty file added sliced_lines/pope-iliad_10.txt
Empty file.
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_100.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Map of the Plain of Troy
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_101.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VENUS, WOUNDED IN THE HAND, CONDUCTED BY IRIS TO MARS
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_102.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OTUS AND EPHIALTES HOLDING MARS CAPTIVE
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_103.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DIOMED CASTING HIS SPEAR AT MARS
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_104.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
JUNO
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_105.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
HECTOR CHIDING PARIS
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_106.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
THE MEETING OF HECTOR AND ANDROMACHE
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_107.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BOWS AND BOW CASE
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_108.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IRIS
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_109.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
HECTOR AND AJAX SEPARATED BY THE HERALDS
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_11.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Author: Homer
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_110.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GREEK AMPHORA—WINE VESSELS
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_111.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
JUNO AND MINERVA GOING TO ASSIST THE GREEKS
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_112.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
THE HOURS TAKING THE HORSES FROM JUNO’S CAR
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_113.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
THE SHIELD OF ACHILLES
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_114.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PLUTO
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_115.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
THE EMBASSY TO ACHILLES
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_116.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GREEK GALLEY
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_117.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PROSERPINE
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_118.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ACHILLES
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_119.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DIOMED AND ULYSSES RETURNING WITH THE SPOILS OF RHESUS
Empty file added sliced_lines/pope-iliad_12.txt
Empty file.
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_120.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
THE DESCENT OF DISCORD
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_121.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
HERCULES
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_122.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
POLYDAMAS ADVISING HECTOR
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_123.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GREEK ALTAR
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_124.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NEPTUNE RISING FROM THE SEA
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_125.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GREEK EARRINGS
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_126.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SLEEP ESCAPING FROM THE WRATH OF JUPITER
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_127.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GREEK SHIELD
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_128.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BACCHUS
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_129.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
AJAX DEFENDING THE GREEK SHIPS
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_13.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Annotator: Theodore Alois Buckley
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_130.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CASTOR AND POLLUX
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_131.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Buckles
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_132.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DIANA
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_133.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SLEEP AND DEATH CONVEYING THE BODY OF SARPEDON TO LYCIA
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_134.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ÆSCULAPIUS
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_135.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FIGHT FOR THE BODY OF PATROCLUS
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_136.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VULCAN FROM AN ANTIQUE GEM
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_137.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
THETIS ORDERING THE NEREIDS TO DESCEND INTO THE SEA
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_138.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
JUNO COMMANDING THE SUN TO SET
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_139.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TRIPOD
Empty file added sliced_lines/pope-iliad_14.txt
Empty file.
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_140.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
THETIS AND EURYNOME RECEIVING THE INFANT VULCAN
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_141.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VULCAN AND CHARIS RECEIVING THETIS
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_142.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
THETIS BRINGING THE ARMOUR TO ACHILLES
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_143.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
HERCULES
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_144.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
THE GODS DESCENDING TO BATTLE
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_145.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CENTAUR
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_146.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ACHILLES CONTENDING WITH THE RIVERS
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_147.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
THE BATH
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_148.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ANDROMACHE FAINTING ON THE WALL
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_149.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
THE FUNERAL PILE OF PATROCLUS
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_15.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Translator: Alexander Pope
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_150.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CERES
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_151.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
HECTOR’S BODY AT THE CAR OF ACHILLES
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_152.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
THE JUDGMENT OF PARIS
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_153.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IRIS ADVISES PRIAM TO OBTAIN THE BODY OF HECTOR
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_154.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FUNERAL OF HECTOR
Empty file added sliced_lines/pope-iliad_155.txt
Empty file.
Empty file added sliced_lines/pope-iliad_156.txt
Empty file.
Empty file added sliced_lines/pope-iliad_157.txt
Empty file.
Empty file added sliced_lines/pope-iliad_158.txt
Empty file.
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_159.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INTRODUCTION.
Empty file added sliced_lines/pope-iliad_16.txt
Empty file.
Empty file added sliced_lines/pope-iliad_160.txt
Empty file.
Empty file added sliced_lines/pope-iliad_161.txt
Empty file.
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_162.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Scepticism is as much the result of knowledge, as knowledge is of
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_163.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scepticism. To be content with what we at present know, is, for the
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_164.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
most part, to shut our ears against conviction; since, from the very
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_165.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gradual character of our education, we must continually forget, and
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_166.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
emancipate ourselves from, knowledge previously acquired; we must set
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_167.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aside old notions and embrace fresh ones; and, as we learn, we must be
1 change: 1 addition & 0 deletions sliced_lines/pope-iliad_168.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
daily unlearning something which it has cost us no small labour and
Loading