Skip to content

Commit 41dcd67

Browse files
committed
exceptions
1 parent ea1e22f commit 41dcd67

File tree

3 files changed

+132
-25
lines changed

3 files changed

+132
-25
lines changed

Diff for: .ipynb_checkpoints/10.Exceptions-checkpoint.ipynb

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"cells": [],
3+
"metadata": {},
4+
"nbformat": 4,
5+
"nbformat_minor": 2
6+
}

Diff for: 09.Directory.ipynb

+29-25
Original file line numberDiff line numberDiff line change
@@ -428,42 +428,46 @@
428428
},
429429
{
430430
"cell_type": "code",
431-
"execution_count": 22,
431+
"execution_count": 23,
432432
"metadata": {},
433-
"outputs": [
434-
{
435-
"ename": "FileNotFoundError",
436-
"evalue": "[Errno 2] No such file or directory: 'tested'",
437-
"output_type": "error",
438-
"traceback": [
439-
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
440-
"\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
441-
"\u001b[0;32m<ipython-input-22-cfe077e3468f>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mshutil\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrmtree\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'tested'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
442-
"\u001b[0;32m~/anaconda3/lib/python3.7/shutil.py\u001b[0m in \u001b[0;36mrmtree\u001b[0;34m(path, ignore_errors, onerror)\u001b[0m\n\u001b[1;32m 480\u001b[0m \u001b[0morig_st\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlstat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 481\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 482\u001b[0;31m \u001b[0monerror\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlstat\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpath\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexc_info\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 483\u001b[0m \u001b[0;32mreturn\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 484\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
443-
"\u001b[0;32m~/anaconda3/lib/python3.7/shutil.py\u001b[0m in \u001b[0;36mrmtree\u001b[0;34m(path, ignore_errors, onerror)\u001b[0m\n\u001b[1;32m 478\u001b[0m \u001b[0;31m# lstat()/open()/fstat() trick.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 479\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 480\u001b[0;31m \u001b[0morig_st\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlstat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 481\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 482\u001b[0m \u001b[0monerror\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlstat\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpath\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexc_info\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
444-
"\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'tested'"
445-
]
446-
}
447-
],
433+
"outputs": [],
448434
"source": [
449435
"shutil.rmtree('tested')"
450436
]
451437
},
452438
{
453439
"cell_type": "code",
454-
"execution_count": null,
440+
"execution_count": 24,
455441
"metadata": {},
456-
"outputs": [],
442+
"outputs": [
443+
{
444+
"data": {
445+
"text/plain": [
446+
"['03.Numpy.ipynb',\n",
447+
" '09.Directory.ipynb',\n",
448+
" 'README.md',\n",
449+
" '.ipynb_checkpoints',\n",
450+
" '02.Arrays.ipynb',\n",
451+
" 'geek.txt',\n",
452+
" '05.InOut.ipynb',\n",
453+
" '08.Dictionary .ipynb',\n",
454+
" '.git',\n",
455+
" '01.Python Basics.ipynb',\n",
456+
" '06.Tuple.ipynb',\n",
457+
" 'test.txt',\n",
458+
" '04.Lists.ipynb',\n",
459+
" 'file.txt',\n",
460+
" '07.Sets.ipynb']"
461+
]
462+
},
463+
"execution_count": 24,
464+
"metadata": {},
465+
"output_type": "execute_result"
466+
}
467+
],
457468
"source": [
458469
"os.listdir()"
459470
]
460-
},
461-
{
462-
"cell_type": "code",
463-
"execution_count": null,
464-
"metadata": {},
465-
"outputs": [],
466-
"source": []
467471
}
468472
],
469473
"metadata": {

Diff for: 10.Exceptions.ipynb

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"import sys"
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": 2,
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"x = ['a', 0, 2]"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": 3,
24+
"metadata": {},
25+
"outputs": [
26+
{
27+
"data": {
28+
"text/plain": [
29+
"['a', 0, 2]"
30+
]
31+
},
32+
"execution_count": 3,
33+
"metadata": {},
34+
"output_type": "execute_result"
35+
}
36+
],
37+
"source": [
38+
"x"
39+
]
40+
},
41+
{
42+
"cell_type": "code",
43+
"execution_count": 6,
44+
"metadata": {},
45+
"outputs": [
46+
{
47+
"ename": "SyntaxError",
48+
"evalue": "invalid syntax (<ipython-input-6-c15acf3b4ceb>, line 1)",
49+
"output_type": "error",
50+
"traceback": [
51+
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-6-c15acf3b4ceb>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m or entry in x:\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
52+
]
53+
}
54+
],
55+
"source": [
56+
"or entry in x:\n",
57+
" try:\n",
58+
" f print(\"The entry is\", entry)\n",
59+
" r = 1/int(entry)\n",
60+
" break\n",
61+
" except:\n",
62+
" print(\"Oops!\",sys.exc_info()[0],\"occured.\")\n",
63+
" print(\"Next entry.\")\n",
64+
" print()\n",
65+
"print(\"The reciprocal of\",entry,\"is\",r)"
66+
]
67+
},
68+
{
69+
"cell_type": "code",
70+
"execution_count": null,
71+
"metadata": {},
72+
"outputs": [],
73+
"source": []
74+
}
75+
],
76+
"metadata": {
77+
"kernelspec": {
78+
"display_name": "Python 3",
79+
"language": "python",
80+
"name": "python3"
81+
},
82+
"language_info": {
83+
"codemirror_mode": {
84+
"name": "ipython",
85+
"version": 3
86+
},
87+
"file_extension": ".py",
88+
"mimetype": "text/x-python",
89+
"name": "python",
90+
"nbconvert_exporter": "python",
91+
"pygments_lexer": "ipython3",
92+
"version": "3.7.3"
93+
}
94+
},
95+
"nbformat": 4,
96+
"nbformat_minor": 2
97+
}

0 commit comments

Comments
 (0)