Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 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": 2,
"metadata": {},
"outputs": [
{
Expand All @@ -27,7 +27,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -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": {
Expand Down