@@ -11848,11 +11848,11 @@ <h2 id="datetime-for-working-with-dates-and-times"><a href="https://docs.python.
11848
11848
11849
11849
11850
11850
< 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
11856
11856
</ pre >
11857
11857
</ div >
11858
11858
</ div >
@@ -11896,8 +11896,8 @@ <h3 id="strftime()"><code>strftime()</code><a class="anchor-link" href="#strftim
11896
11896
11897
11897
11898
11898
< 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
11901
11901
</ pre >
11902
11902
</ div >
11903
11903
</ div >
@@ -11984,7 +11984,7 @@ <h3 id="timedelta"><a href="https://docs.python.org/3/library/datetime.html#time
11984
11984
11985
11985
11986
11986
< 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
11988
11988
tomorrow - now = 1 day, 0:00:00
11989
11989
days: 1, seconds: 0
11990
11990
total seconds: 86400.0
@@ -12077,10 +12077,10 @@ <h3 id="Working-with-timezones">Working with timezones<a class="anchor-link" hre
12077
12077
12078
12078
12079
12079
< 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
12084
12084
</ pre >
12085
12085
</ div >
12086
12086
</ div >
@@ -12153,13 +12153,60 @@ <h2 id="logging"><a href="https://docs.python.org/3/library/logging.html#module-
12153
12153
</ div >
12154
12154
< div class ="inner_cell ">
12155
12155
< 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
+
12157
12158
</ div >
12158
12159
</ div >
12159
12160
</ div >
12160
12161
< div class ="cell border-box-sizing code_cell rendered ">
12161
12162
< div class ="input ">
12162
12163
< 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 >
12163
12210
< div class ="inner_cell ">
12164
12211
< div class ="input_area ">
12165
12212
< 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
12191
12238
12192
12239
12193
12240
< 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
12196
12243
</ pre >
12197
12244
</ div >
12198
12245
</ div >
@@ -12211,7 +12258,7 @@ <h2 id="random-for-random-number-generation"><a href="https://docs.python.org/3/
12211
12258
</ div >
12212
12259
< div class ="cell border-box-sizing code_cell rendered ">
12213
12260
< div class ="input ">
12214
- < div class ="prompt input_prompt "> In [9 ]:</ div >
12261
+ < div class ="prompt input_prompt "> In [10 ]:</ div >
12215
12262
< div class ="inner_cell ">
12216
12263
< div class ="input_area ">
12217
12264
< 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/
12237
12284
12238
12285
12239
12286
< 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
12242
12289
</ pre >
12243
12290
</ div >
12244
12291
</ div >
@@ -12258,7 +12305,7 @@ <h2 id="random-for-random-number-generation"><a href="https://docs.python.org/3/
12258
12305
</ div >
12259
12306
< div class ="cell border-box-sizing code_cell rendered ">
12260
12307
< div class ="input ">
12261
- < div class ="prompt input_prompt "> In [10 ]:</ div >
12308
+ < div class ="prompt input_prompt "> In [11 ]:</ div >
12262
12309
< div class ="inner_cell ">
12263
12310
< div class ="input_area ">
12264
12311
< 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="#
12320
12367
</ div >
12321
12368
< div class ="cell border-box-sizing code_cell rendered ">
12322
12369
< div class ="input ">
12323
- < div class ="prompt input_prompt "> In [11 ]:</ div >
12370
+ < div class ="prompt input_prompt "> In [12 ]:</ div >
12324
12371
< div class ="inner_cell ">
12325
12372
< div class ="input_area ">
12326
12373
< 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
12373
12420
</ div >
12374
12421
< div class ="cell border-box-sizing code_cell rendered ">
12375
12422
< div class ="input ">
12376
- < div class ="prompt input_prompt "> In [12 ]:</ div >
12423
+ < div class ="prompt input_prompt "> In [13 ]:</ div >
12377
12424
< div class ="inner_cell ">
12378
12425
< div class ="input_area ">
12379
12426
< div class =" highlight hl-ipython3 "> < pre > < span > </ span > < span class ="kn "> import</ span > < span class ="nn "> re</ span >
0 commit comments