Skip to content

Commit 5dfcb6f

Browse files
committed
add new libaries
1 parent 3afe0bb commit 5dfcb6f

File tree

5 files changed

+87
-33
lines changed

5 files changed

+87
-33
lines changed

20python_lbraries.html

Lines changed: 61 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -71,39 +71,42 @@ <h4>
7171
<div class="photo">
7272
<img src="img/20python_lib.png" alt="python" border="1" height="256" width="256">
7373
</div>
74-
< class="info">
75-
<h2>
76-
20 Python Libraries You Aren't Using!
77-
</h2>
78-
<h6>
79-
Author: Akash Singh <br/>Date: December 20, 2019
80-
</h6>
81-
<br><br>
82-
<p style="color:black;font-size:20px;">
83-
I have been using Python for quite a while now, still learning a lot of simple and
84-
new things. Sometimes these simple things saves time and bring a lot of joy to me. I
85-
will be sharing a breif overview of the book:
86-
<blockquote><q>20 Python Libraries You Aren't Using
87-
(But Should)</q> - <b>Caleb Hattingh</b></blockquote>
88-
<p style="color:black;font-size:20px;">This book primarily focuses on some of the lesser-known libraries from the third-party ecosystem.</p>
89-
<ol>Libraries</ol>
90-
<ul style="color:black;font-size:20px;">
74+
<h2>
75+
20 Python Libraries You Aren't Using!
76+
</h2>
77+
<h6>
78+
Author: Akash Singh <br/>Date: December 20, 2019
79+
</h6>
80+
<br><br>
81+
<p style="color:black;font-size:18px;">
82+
I have been using Python for quite a while now, still learning a lot of simple and
83+
new things. Sometimes these simple things saves time and bring a lot of joy to me. I
84+
will be sharing a breif overview of the book:
85+
<blockquote><q>20 Python Libraries You Aren't Using
86+
(But Should)</q> - <b>Caleb Hattingh</b></blockquote>
87+
<p style="color:black;font-size:px;">This book primarily focuses on some of the
88+
lesser-known libraries from the third-party ecosystem.</p>
89+
<ol style="color:black;font-size:18px;">Libraries
90+
<li>Standard Library</li>16
91+
<ul style="color:black;font-size:18px;">
9192
<li>collections.OrderedDict: gives you a <i>dict</i> that maintains the order of
9293
insertion.
9394
</li>
9495
<li>collections.defaultdict: allows you to specify a default value to all new
9596
keys.
9697
</li>
9798
For example:
98-
<pre>
99+
<pre>
99100
<code>
100101
>>> import collections
101102
>>> d = collections.defaultdict(list)
102103
>>> d['random_key']
103104
[] # output -> auto-initilized to list
104105
</code>
105106
</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>
107110
<pre>
108111
<code>
109112
>>> point = (1.0, 2.0)
@@ -114,34 +117,59 @@ <h6>
114117
1.0
115118
</code>
116119
</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.
119129
<pre>
120130
<code>
121131
@contextmanager
122132

123133
</code>
124134
</pre>
125-
<li>concurrent.futures: </li>
135+
<li>concurrent.futures:</li>
126136
<li>logging</li>
127137
<li>sched</li>
128138
</ul>
139+
<li>Command-Line Applications:</li>
140+
<ol>
141+
<li>Colorama: Allows you to use colors in your output.
142+
<pre>
143+
<img src="img/colorama.png"/>
144+
<a href="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/>
147+
<img src="img/log_colors.png"/><a href="code/colorlogs_code.py">download code</a>
148+
</li>
149+
<div class="card" style="width: 60rem;">
150+
<div class="card-body">
151+
<h5 class="card-title">Special title treatment</h5>
152+
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
153+
<a href="#" >Go somewhere</a>
154+
</div>
155+
</div> </ol>
156+
</ol>
129157

130-
</p>
131-
</div>
158+
</p>
132159
</div>
133-
<div class="break"></div>
134-
</section><!-- content -->
135160
</div>
161+
<div class="break"></div>
162+
</section><!-- content -->
136163
</div>
137164
</div>
138-
<!-- End Tab Container -->
139-
<footer>
140-
<p>
141-
Copyright &#x000A9;&nbsp;2017 &#x000B7; Akash Singh
142-
</p>
143-
</footer>
144-
</div><!-- #main -->
165+
</div>
166+
<!-- End Tab Container -->
167+
<footer>
168+
<p>
169+
Copyright &#x000A9;&nbsp;2017 &#x000B7; Akash Singh
170+
</p>
171+
</footer>
172+
</div><!-- #main -->
145173
</div><!-- #main-container -->
146174

147175

code/colorama_code.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from colorama import init, Fore, Back, Style
2+
3+
init(autoreset=True) # maps ANSI color code to OS system
4+
5+
messages = [
6+
'Colorama test case ',
7+
(Fore.LIGHTYELLOW_EX + Style.BRIGHT + Back.MAGENTA + 'Colored message on terminal!!!!!'),
8+
'Another message but not colored'
9+
]
10+
11+
for m in messages:
12+
print(m)

code/colorlogs_code.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import colorlog
2+
3+
logger = colorlog.getLogger()
4+
logger.setLevel(colorlog.colorlog.logging.DEBUG)
5+
6+
handler = colorlog.StreamHandler()
7+
handler.setFormatter(colorlog.ColoredFormatter())
8+
logger.addHandler(handler)
9+
10+
logger.debug('debug message')
11+
logger.info('information message')
12+
logger.warning('warning message')
13+
logger.error('error message')
14+
logger.critical('critical message')

img/colorama.png

7.85 KB
Loading

img/log_colors.png

14.2 KB
Loading

0 commit comments

Comments
 (0)