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
  •  
  •  
  •  
74 changes: 54 additions & 20 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": 4,
"metadata": {},
"outputs": [
{
Expand All @@ -27,7 +27,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -43,7 +43,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -55,7 +55,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -99,7 +99,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -108,7 +108,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -119,20 +119,9 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"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 +135,7 @@
},
{
"cell_type": "code",
"execution_count": 50,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -155,6 +144,51 @@
" with open(iliad_file, \"r\") as f:\n",
" a.write(f.read() + \"\\n\")\n"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"with open(outfile, \"a\") as a:\n",
" for iliad_file in Path(\".\").glob(\"iliad_*.txt\"):\n",
" with open(iliad_file, \"r\") as f:\n",
" text = a.write(f.read() + \"\\n\")\n"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
"filename = \"pope-iliad\"\n",
"with open(f\"./{filename}.txt\", \"r\") as f:\n",
" text = f.read()"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"lines = text.splitlines()\n",
"sliced_lines = lines[:1000] "
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
"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
Loading