Skip to content

Commit aeeb4ac

Browse files
changes
1 parent eed2fd4 commit aeeb4ac

18 files changed

+5241
-653
lines changed

DB/OracleConnection.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import cx_Oracle
2+
import config
3+
import pandas as pd
4+
5+
connection = None
6+
try:
7+
connection = cx_Oracle.connect(
8+
"hr",
9+
"hr",
10+
"xe",
11+
encoding='UTF-8')
12+
13+
# show the version of the Oracle Database
14+
print(connection.version)
15+
df = pd.read_sql('select * from employees',connection)
16+
print(df.head())
17+
except cx_Oracle.Error as error:
18+
print(error)
19+
finally:
20+
# release the connection
21+
if connection:
22+
connection.close()

ExceptionHandling/.ipynb_checkpoints/ExceptionHandling-checkpoint.ipynb

Lines changed: 206 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
},
6363
{
6464
"cell_type": "code",
65-
"execution_count": 2,
65+
"execution_count": 9,
6666
"metadata": {},
6767
"outputs": [
6868
{
@@ -72,7 +72,7 @@
7272
"traceback": [
7373
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
7474
"\u001b[1;31mZeroDivisionError\u001b[0m Traceback (most recent call last)",
75-
"\u001b[1;32m<ipython-input-2-9500656ba1ce>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m10\u001b[0m \u001b[1;33m*\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m/\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
75+
"\u001b[1;32m<ipython-input-9-9500656ba1ce>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m10\u001b[0m \u001b[1;33m*\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m/\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
7676
"\u001b[1;31mZeroDivisionError\u001b[0m: division by zero"
7777
]
7878
}
@@ -83,7 +83,7 @@
8383
},
8484
{
8585
"cell_type": "code",
86-
"execution_count": 3,
86+
"execution_count": 10,
8787
"metadata": {},
8888
"outputs": [
8989
{
@@ -93,7 +93,7 @@
9393
"traceback": [
9494
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
9595
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
96-
"\u001b[1;32m<ipython-input-3-eb3d99f57752>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m4\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mspam\u001b[0m\u001b[1;33m*\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
96+
"\u001b[1;32m<ipython-input-10-eb3d99f57752>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m4\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mspam\u001b[0m\u001b[1;33m*\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
9797
"\u001b[1;31mNameError\u001b[0m: name 'spam' is not defined"
9898
]
9999
}
@@ -104,7 +104,7 @@
104104
},
105105
{
106106
"cell_type": "code",
107-
"execution_count": 4,
107+
"execution_count": 11,
108108
"metadata": {},
109109
"outputs": [
110110
{
@@ -114,7 +114,7 @@
114114
"traceback": [
115115
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
116116
"\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)",
117-
"\u001b[1;32m<ipython-input-4-f01985f6a385>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'2'\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;36m2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
117+
"\u001b[1;32m<ipython-input-11-f01985f6a385>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'2'\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;36m2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
118118
"\u001b[1;31mTypeError\u001b[0m: can only concatenate str (not \"int\") to str"
119119
]
120120
}
@@ -123,6 +123,50 @@
123123
"print('2' + 2)"
124124
]
125125
},
126+
{
127+
"cell_type": "code",
128+
"execution_count": 12,
129+
"metadata": {},
130+
"outputs": [
131+
{
132+
"ename": "ValueError",
133+
"evalue": "substring not found",
134+
"output_type": "error",
135+
"traceback": [
136+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
137+
"\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)",
138+
"\u001b[1;32m<ipython-input-12-7e8d2962be5c>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mstring0\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'Hello World'\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mstring0\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mindex\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'india'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
139+
"\u001b[1;31mValueError\u001b[0m: substring not found"
140+
]
141+
}
142+
],
143+
"source": [
144+
"string0='Hello World'\n",
145+
"string0.index('india')"
146+
]
147+
},
148+
{
149+
"cell_type": "code",
150+
"execution_count": 13,
151+
"metadata": {},
152+
"outputs": [
153+
{
154+
"ename": "IndexError",
155+
"evalue": "string index out of range",
156+
"output_type": "error",
157+
"traceback": [
158+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
159+
"\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)",
160+
"\u001b[1;32m<ipython-input-13-cb2f44dfef1c>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mstring0\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'Hello World'\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mstring0\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m12\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
161+
"\u001b[1;31mIndexError\u001b[0m: string index out of range"
162+
]
163+
}
164+
],
165+
"source": [
166+
"string0='Hello World'\n",
167+
"string0[12]"
168+
]
169+
},
126170
{
127171
"cell_type": "markdown",
128172
"metadata": {},
@@ -145,29 +189,66 @@
145189
},
146190
{
147191
"cell_type": "code",
148-
"execution_count": 2,
192+
"execution_count": 18,
193+
"metadata": {},
194+
"outputs": [
195+
{
196+
"name": "stdout",
197+
"output_type": "stream",
198+
"text": [
199+
"Please enter a number: sdasdasd\n"
200+
]
201+
},
202+
{
203+
"ename": "ValueError",
204+
"evalue": "invalid literal for int() with base 10: 'sdasdasd'",
205+
"output_type": "error",
206+
"traceback": [
207+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
208+
"\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)",
209+
"\u001b[1;32m<ipython-input-18-1cd50bb8690f>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[1;31m# try:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[0mx\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minput\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Please enter a number: \"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 5\u001b[0m \u001b[1;31m# break\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;31m# except ValueError:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
210+
"\u001b[1;31mValueError\u001b[0m: invalid literal for int() with base 10: 'sdasdasd'"
211+
]
212+
}
213+
],
214+
"source": [
215+
"# while True:\n",
216+
"\n",
217+
"x = int(input(\"Please enter a number: \"))\n",
218+
"y=20\n",
219+
"print(y**3)\n",
220+
"print('done')"
221+
]
222+
},
223+
{
224+
"cell_type": "code",
225+
"execution_count": 17,
149226
"metadata": {},
150227
"outputs": [
151228
{
152229
"name": "stdout",
153230
"output_type": "stream",
154231
"text": [
155-
"Please enter a number: a\n",
232+
"Please enter a number: asdas\n",
156233
"invalid literal for int() with base 10: \n",
157234
"Oops! That was no valid number. Try again...\n",
158-
"Please enter a number: 1\n"
235+
"8000\n",
236+
"done\n"
159237
]
160238
}
161239
],
162240
"source": [
163-
"while True:\n",
241+
"# while True:\n",
164242
" \n",
165-
" try:\n",
166-
" x = int(input(\"Please enter a number: \"))\n",
167-
" break\n",
168-
" except ValueError:\n",
169-
" print('invalid literal for int() with base 10: ')\n",
170-
" print(\"Oops! That was no valid number. Try again...\")"
243+
"try:\n",
244+
" x = int(input(\"Please enter a number: \"))\n",
245+
"# break\n",
246+
"except ValueError:\n",
247+
" print('invalid literal for int() with base 10: ')\n",
248+
" print(\"Oops! That was no valid number. Try again...\")\n",
249+
"y=20\n",
250+
"print(y**3)\n",
251+
"print('done')"
171252
]
172253
},
173254
{
@@ -297,20 +378,47 @@
297378
],
298379
"source": [
299380
"import sys\n",
300-
"\n",
301381
"try:\n",
302382
" f = open('myfile.txt')\n",
303383
" s = f.readline()\n",
304384
" i = int(s.strip())\n",
305385
"except OSError as err:\n",
306386
" print(\"OS error: {0}\".format(err))\n",
387+
" print(\"Unexpected error:\", sys.exc_info()[0],sys.exc_info()[1])\n",
307388
"except ValueError:\n",
308389
" print(\"Could not convert data to an integer.\")\n",
309390
"except:\n",
310391
" print(\"Unexpected error:\", sys.exc_info()[0],sys.exc_info()[1])\n",
311392
" raise"
312393
]
313394
},
395+
{
396+
"cell_type": "code",
397+
"execution_count": 19,
398+
"metadata": {},
399+
"outputs": [
400+
{
401+
"data": {
402+
"text/plain": [
403+
"(32, 40)"
404+
]
405+
},
406+
"execution_count": 19,
407+
"metadata": {},
408+
"output_type": "execute_result"
409+
}
410+
],
411+
"source": [
412+
"# a=10\n",
413+
"# size(a)\n",
414+
"\n",
415+
"import sys\n",
416+
"# sys.getsizeof(a)\n",
417+
"a=(1,2,3)\n",
418+
"b=[1,2,3]\n",
419+
"sys.getsizeof(a),sys.getsizeof(b)\n"
420+
]
421+
},
314422
{
315423
"cell_type": "markdown",
316424
"metadata": {},
@@ -436,6 +544,86 @@
436544
"# Handling run-time error: division by zero"
437545
]
438546
},
547+
{
548+
"cell_type": "code",
549+
"execution_count": 5,
550+
"metadata": {},
551+
"outputs": [
552+
{
553+
"name": "stdout",
554+
"output_type": "stream",
555+
"text": [
556+
"*** print_tb:\n",
557+
" File \"<ipython-input-5-1685af91a914>\", line 9, in <module>\n",
558+
" lumberjack()\n",
559+
"*** print_exception:\n",
560+
"Traceback (most recent call last):\n",
561+
" File \"<ipython-input-5-1685af91a914>\", line 9, in <module>\n",
562+
" lumberjack()\n",
563+
" File \"<ipython-input-5-1685af91a914>\", line 3, in lumberjack\n",
564+
" bright_side_of_death()\n",
565+
"IndexError: tuple index out of range\n",
566+
"*** print_exc:\n",
567+
"*** format_exc, first and last line:\n",
568+
"Traceback (most recent call last):\n",
569+
"IndexError: tuple index out of range\n",
570+
"*** format_exception:\n",
571+
"['Traceback (most recent call last):\\n', ' File \"<ipython-input-5-1685af91a914>\", line 9, in <module>\\n lumberjack()\\n', ' File \"<ipython-input-5-1685af91a914>\", line 3, in lumberjack\\n bright_side_of_death()\\n', ' File \"<ipython-input-5-1685af91a914>\", line 6, in bright_side_of_death\\n return tuple()[0]\\n', 'IndexError: tuple index out of range\\n']\n",
572+
"*** extract_tb:\n",
573+
"[<FrameSummary file <ipython-input-5-1685af91a914>, line 9 in <module>>, <FrameSummary file <ipython-input-5-1685af91a914>, line 3 in lumberjack>, <FrameSummary file <ipython-input-5-1685af91a914>, line 6 in bright_side_of_death>]\n",
574+
"*** format_tb:\n",
575+
"[' File \"<ipython-input-5-1685af91a914>\", line 9, in <module>\\n lumberjack()\\n', ' File \"<ipython-input-5-1685af91a914>\", line 3, in lumberjack\\n bright_side_of_death()\\n', ' File \"<ipython-input-5-1685af91a914>\", line 6, in bright_side_of_death\\n return tuple()[0]\\n']\n",
576+
"*** tb_lineno: 9\n"
577+
]
578+
},
579+
{
580+
"name": "stderr",
581+
"output_type": "stream",
582+
"text": [
583+
"Traceback (most recent call last):\n",
584+
" File \"<ipython-input-5-1685af91a914>\", line 9, in <module>\n",
585+
" lumberjack()\n",
586+
" File \"<ipython-input-5-1685af91a914>\", line 3, in lumberjack\n",
587+
" bright_side_of_death()\n",
588+
" File \"<ipython-input-5-1685af91a914>\", line 6, in bright_side_of_death\n",
589+
" return tuple()[0]\n",
590+
"IndexError: tuple index out of range\n"
591+
]
592+
}
593+
],
594+
"source": [
595+
"import sys,traceback\n",
596+
"def lumberjack():\n",
597+
" bright_side_of_death()\n",
598+
"\n",
599+
"def bright_side_of_death():\n",
600+
" return tuple()[0]\n",
601+
"\n",
602+
"try:\n",
603+
" lumberjack()\n",
604+
"except IndexError:\n",
605+
" exc_type, exc_value, exc_traceback = sys.exc_info()\n",
606+
" print(\"*** print_tb:\")\n",
607+
" traceback.print_tb(exc_traceback, limit=1, file=sys.stdout)\n",
608+
" print(\"*** print_exception:\")\n",
609+
" traceback.print_exception(exc_type, exc_value, exc_traceback,\n",
610+
" limit=2, file=sys.stdout)\n",
611+
" print( \"*** print_exc:\")\n",
612+
" traceback.print_exc()\n",
613+
" print( \"*** format_exc, first and last line:\")\n",
614+
" formatted_lines = traceback.format_exc().splitlines()\n",
615+
" print( formatted_lines[0])\n",
616+
" print( formatted_lines[-1])\n",
617+
" print( \"*** format_exception:\")\n",
618+
" print( repr(traceback.format_exception(exc_type, exc_value,\n",
619+
" exc_traceback)))\n",
620+
" print( \"*** extract_tb:\")\n",
621+
" print( repr(traceback.extract_tb(exc_traceback)))\n",
622+
" print( \"*** format_tb:\")\n",
623+
" print( repr(traceback.format_tb(exc_traceback)))\n",
624+
" print( \"*** tb_lineno:\", exc_traceback.tb_lineno)"
625+
]
626+
},
439627
{
440628
"cell_type": "markdown",
441629
"metadata": {},
@@ -847,7 +1035,7 @@
8471035
"name": "python",
8481036
"nbconvert_exporter": "python",
8491037
"pygments_lexer": "ipython3",
850-
"version": "3.7.1"
1038+
"version": "3.8.5"
8511039
}
8521040
},
8531041
"nbformat": 4,

0 commit comments

Comments
 (0)