You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<pstyle="color:black;font-size:px;">This book primarily focuses on some of the
88
+
lesser-known libraries from the third-party ecosystem.</p>
89
+
<olstyle="color:black;font-size:18px;">Libraries
90
+
<li>Standard Library</li>16
91
+
<ulstyle="color:black;font-size:18px;">
91
92
<li>collections.OrderedDict: gives you a <i>dict</i> that maintains the order of
92
93
insertion.
93
94
</li>
94
95
<li>collections.defaultdict: allows you to specify a default value to all new
95
96
keys.
96
97
</li>
97
98
For example:
98
-
<pre>
99
+
<pre>
99
100
<code>
100
101
>>> import collections
101
102
>>> d = collections.defaultdict(list)
102
103
>>> d['random_key']
103
104
[] # output -> auto-initilized to list
104
105
</code>
105
106
</pre>
106
-
<li>collections.namedtuple: namedtuple incurs no extra runtime cost and can make your much easier to read.</li>
107
+
<li>collections.namedtuple: namedtuple incurs no extra runtime cost and can make
108
+
your much easier to read.
109
+
</li>
107
110
<pre>
108
111
<code>
109
112
>>> point = (1.0, 2.0)
@@ -114,34 +117,59 @@ <h6>
114
117
1.0
115
118
</code>
116
119
</pre>
117
-
<li>contextlib: context manager is what simplifies cleanup step. It is what you use with the <i>with</i> statement. You can use the <i>contextmanager</i> decorator from the contextlib libary to create your own context manager.</li>
118
-
Though the default, “low level” way to make a context manager is to make a class which follows the context management protocol, by implementing <i>__enter__</i> and <i>__exit__</i> methods, the simplest way is using the contextmanager decorator from the contextlib library, and invoking yield in your context manager function in between the setup and teardown steps.
120
+
<li>contextlib: context manager is what simplifies cleanup step. It is what you use
121
+
with the <i>with</i> statement. You can use the <i>contextmanager</i> decorator
122
+
from the contextlib libary to create your own context manager.
123
+
</li>
124
+
Though the default, “low level” way to make a context manager is to make a class
125
+
which follows the context management protocol, by implementing <i>__enter__</i> and
126
+
<i>__exit__</i> methods, the simplest way is using the contextmanager decorator from
127
+
the contextlib library, and invoking yield in your context manager function in
128
+
between the setup and teardown steps.
119
129
<pre>
120
130
<code>
121
131
@contextmanager
122
132
123
133
</code>
124
134
</pre>
125
-
<li>concurrent.futures:</li>
135
+
<li>concurrent.futures:</li>
126
136
<li>logging</li>
127
137
<li>sched</li>
128
138
</ul>
139
+
<li>Command-Line Applications:</li>
140
+
<ol>
141
+
<li>Colorama: Allows you to use colors in your output.
142
+
<pre>
143
+
<imgsrc="img/colorama.png"/>
144
+
<ahref="code/colorama_code.py">Click here to download the sample code</a>
145
+
</pre>
146
+
But many a times this is not our use case and we want colors in out logs. This can be achieved using library <b>colorlogs</b>.<br/>
0 commit comments