@@ -11848,11 +11848,11 @@ <h2 id="datetime-for-working-with-dates-and-times"><a href="https://docs.python.
1184811848
1184911849
1185011850< div class ="output_subarea output_stream output_stdout output_text ">
11851- < pre > local now: 2018-07-08 12:07:23.620463
11852- utc now: 2018-07-08 10:07:23.620661
11853- 2018 7 8 12 7 23
11854- date: 2018-07-08
11855- time: 12:07:23.620463
11851+ < pre > local now: 2018-09-19 22:00:35.202267
11852+ utc now: 2018-09-19 20:00:35.202567
11853+ 2018 9 19 22 0 35
11854+ date: 2018-09-19
11855+ time: 22:00:35.202267
1185611856</ pre >
1185711857</ div >
1185811858</ div >
@@ -11896,8 +11896,8 @@ <h3 id="strftime()"><code>strftime()</code><a class="anchor-link" href="#strftim
1189611896
1189711897
1189811898< div class ="output_subarea output_stream output_stdout output_text ">
11899- < pre > 2018/07/08-12:07:23
11900- date: 2018-07-08 time:12:07:23
11899+ < pre > 2018/09/19-22:00:35
11900+ date: 2018-09-19 time:22:00:35
1190111901</ pre >
1190211902</ div >
1190311903</ div >
@@ -11984,7 +11984,7 @@ <h3 id="timedelta"><a href="https://docs.python.org/3/library/datetime.html#time
1198411984
1198511985
1198611986< div class ="output_subarea output_stream output_stdout output_text ">
11987- < pre > tomorrow this time: 2018-07-09 12:07:23.620463
11987+ < pre > tomorrow this time: 2018-09-20 22:00:35.202267
1198811988tomorrow - now = 1 day, 0:00:00
1198911989days: 1, seconds: 0
1199011990total seconds: 86400.0
@@ -12077,10 +12077,10 @@ <h3 id="Working-with-timezones">Working with timezones<a class="anchor-link" hre
1207712077
1207812078
1207912079< div class ="output_subarea output_stream output_stdout output_text ">
12080- < pre > naive utc now: 2018-07-08 10:07:24.490800 , tzinfo: None
12081- utc now: 2018-07-08 10:07:24.490800 +00:00, tzinfo: UTC
12082- Paris: 2018-07-08 12:07:24.490800 +02:00, tzinfo: Europe/Paris
12083- New York: 2018-07-08 06:07:24.490800 -04:00, tzinfo: America/New_York
12080+ < pre > naive utc now: 2018-09-19 20:00:36.074664 , tzinfo: None
12081+ utc now: 2018-09-19 20:00:36.074664 +00:00, tzinfo: UTC
12082+ Paris: 2018-09-19 22:00:36.074664 +02:00, tzinfo: Europe/Paris
12083+ New York: 2018-09-19 16:00:36.074664 -04:00, tzinfo: America/New_York
1208412084</ pre >
1208512085</ div >
1208612086</ div >
@@ -12153,13 +12153,60 @@ <h2 id="logging"><a href="https://docs.python.org/3/library/logging.html#module-
1215312153</ div >
1215412154< div class ="inner_cell ">
1215512155< div class ="text_cell_render border-box-sizing rendered_html ">
12156- < h3 id ="Formatting-log-entries "> Formatting log entries< a class ="anchor-link " href ="#Formatting-log-entries "> ¶</ a > </ h3 >
12156+ < h3 id ="Logging-expections "> Logging expections< a class ="anchor-link " href ="#Logging-expections "> ¶</ a > </ h3 > < p > There's a neat < code > exception</ code > function in < code > logging</ code > module which will automatically log the stack trace in addition to user defined log entry.</ p >
12157+
1215712158</ div >
1215812159</ div >
1215912160</ div >
1216012161< div class ="cell border-box-sizing code_cell rendered ">
1216112162< div class ="input ">
1216212163< div class ="prompt input_prompt "> In [8]:</ div >
12164+ < div class ="inner_cell ">
12165+ < div class ="input_area ">
12166+ < div class =" highlight hl-ipython3 "> < pre > < span > </ span > < span class ="k "> try</ span > < span class ="p "> :</ span >
12167+ < span class ="n "> path_calculation</ span > < span class ="o "> =</ span > < span class ="mi "> 1</ span > < span class ="o "> /</ span > < span class ="mi "> 0</ span >
12168+ < span class ="k "> except</ span > < span class ="ne "> ZeroDivisionError</ span > < span class ="p "> :</ span >
12169+ < span class ="n "> logging</ span > < span class ="o "> .</ span > < span class ="n "> exception</ span > < span class ="p "> (</ span > < span class ="s1 "> 'All went south in my calculation'</ span > < span class ="p "> )</ span >
12170+ </ pre > </ div >
12171+
12172+ </ div >
12173+ </ div >
12174+ </ div >
12175+
12176+ < div class ="output_wrapper ">
12177+ < div class ="output ">
12178+
12179+
12180+ < div class ="output_area ">
12181+
12182+ < div class ="prompt "> </ div >
12183+
12184+
12185+ < div class ="output_subarea output_stream output_stderr output_text ">
12186+ < pre > ERROR:root:All went south in my calculation
12187+ Traceback (most recent call last):
12188+ File "<ipython-input-8-ccd7d25e79b7>", line 2, in <module>
12189+ path_calculation = 1 / 0
12190+ ZeroDivisionError: division by zero
12191+ </ pre >
12192+ </ div >
12193+ </ div >
12194+
12195+ </ div >
12196+ </ div >
12197+
12198+ </ div >
12199+ < div class ="cell border-box-sizing text_cell rendered "> < div class ="prompt input_prompt ">
12200+ </ div >
12201+ < div class ="inner_cell ">
12202+ < div class ="text_cell_render border-box-sizing rendered_html ">
12203+ < h3 id ="Formatting-log-entries "> Formatting log entries< a class ="anchor-link " href ="#Formatting-log-entries "> ¶</ a > </ h3 >
12204+ </ div >
12205+ </ div >
12206+ </ div >
12207+ < div class ="cell border-box-sizing code_cell rendered ">
12208+ < div class ="input ">
12209+ < div class ="prompt input_prompt "> In [9]:</ div >
1216312210< div class ="inner_cell ">
1216412211 < div class ="input_area ">
1216512212< div class =" highlight hl-ipython3 "> < pre > < span > </ span > < span class ="kn "> import</ span > < span class ="nn "> logging</ span >
@@ -12191,8 +12238,8 @@ <h3 id="Formatting-log-entries">Formatting log entries<a class="anchor-link" hre
1219112238
1219212239
1219312240< div class ="output_subarea output_stream output_stderr output_text ">
12194- < pre > 2018-07-08 12:07:24,540 | MyLogger | WARNING | Something bad is going to happen
12195- 2018-07-08 12:07:24,541 | MyLogger | ERROR | Uups, it already happened
12241+ < pre > 2018-09-19 22:00:36,127 | MyLogger | WARNING | Something bad is going to happen
12242+ 2018-09-19 22:00:36,128 | MyLogger | ERROR | Uups, it already happened
1219612243</ pre >
1219712244</ div >
1219812245</ div >
@@ -12211,7 +12258,7 @@ <h2 id="random-for-random-number-generation"><a href="https://docs.python.org/3/
1221112258</ div >
1221212259< div class ="cell border-box-sizing code_cell rendered ">
1221312260< div class ="input ">
12214- < div class ="prompt input_prompt "> In [9 ]:</ div >
12261+ < div class ="prompt input_prompt "> In [10 ]:</ div >
1221512262< div class ="inner_cell ">
1221612263 < div class ="input_area ">
1221712264< div class =" highlight hl-ipython3 "> < pre > < span > </ span > < span class ="kn "> import</ span > < span class ="nn "> random</ span >
@@ -12237,8 +12284,8 @@ <h2 id="random-for-random-number-generation"><a href="https://docs.python.org/3/
1223712284
1223812285
1223912286< div class ="output_subarea output_stream output_stdout output_text ">
12240- < pre > random integer between 1-100: 35
12241- random float between 0-1: 0.09367732583402133
12287+ < pre > random integer between 1-100: 63
12288+ random float between 0-1: 0.11984811411151686
1224212289</ pre >
1224312290</ div >
1224412291</ div >
@@ -12258,7 +12305,7 @@ <h2 id="random-for-random-number-generation"><a href="https://docs.python.org/3/
1225812305</ div >
1225912306< div class ="cell border-box-sizing code_cell rendered ">
1226012307< div class ="input ">
12261- < div class ="prompt input_prompt "> In [10 ]:</ div >
12308+ < div class ="prompt input_prompt "> In [11 ]:</ div >
1226212309< div class ="inner_cell ">
1226312310 < div class ="input_area ">
1226412311< div class =" highlight hl-ipython3 "> < pre > < span > </ span > < span class ="kn "> import</ span > < span class ="nn "> random</ span >
@@ -12320,7 +12367,7 @@ <h3 id="Searching-occurences">Searching occurences<a class="anchor-link" href="#
1232012367</ div >
1232112368< div class ="cell border-box-sizing code_cell rendered ">
1232212369< div class ="input ">
12323- < div class ="prompt input_prompt "> In [11 ]:</ div >
12370+ < div class ="prompt input_prompt "> In [12 ]:</ div >
1232412371< div class ="inner_cell ">
1232512372 < div class ="input_area ">
1232612373< div class =" highlight hl-ipython3 "> < pre > < span > </ span > < span class ="kn "> import</ span > < span class ="nn "> re</ span >
@@ -12373,7 +12420,7 @@ <h3 id="Variable-validation">Variable validation<a class="anchor-link" href="#Va
1237312420</ div >
1237412421< div class ="cell border-box-sizing code_cell rendered ">
1237512422< div class ="input ">
12376- < div class ="prompt input_prompt "> In [12 ]:</ div >
12423+ < div class ="prompt input_prompt "> In [13 ]:</ div >
1237712424< div class ="inner_cell ">
1237812425 < div class ="input_area ">
1237912426< div class =" highlight hl-ipython3 "> < pre > < span > </ span > < span class ="kn "> import</ span > < span class ="nn "> re</ span >
0 commit comments