Skip to content

Commit 7f31af5

Browse files
committed
Libraries
1 parent 6f7b3b4 commit 7f31af5

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

README.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,13 +1465,14 @@ Argparse
14651465
--------
14661466
```python
14671467
from argparse import ArgumentParser
1468-
parser = ArgumentParser(description='calculate X to the power of Y')
1469-
group = parser.add_mutually_exclusive_group()
1468+
desc = 'calculate X to the power of Y'
1469+
parser = ArgumentParser(description=desc)
1470+
group = parser.add_mutually_exclusive_group()
14701471
group.add_argument('-v', '--verbose', action='store_true')
14711472
group.add_argument('-q', '--quiet', action='store_true')
14721473
parser.add_argument('x', type=int, help='the base')
14731474
parser.add_argument('y', type=int, help='the exponent')
1474-
args = parser.parse_args()
1475+
args = parser.parse_args()
14751476
answer = args.x ** args.y
14761477

14771478
if args.quiet:
@@ -1490,8 +1491,8 @@ Table
14901491
# $ pip3 install tabulate
14911492
from csv import reader
14921493
from tabulate import tabulate
1493-
with open(<filename>, encoding='utf-8', newline='') as csv_file:
1494-
reader = reader(csv_file, delimiter=';')
1494+
with open(<filename>, encoding='utf-8', newline='') as file:
1495+
reader = reader(file, delimiter=';')
14951496
headers = [a.title() for a in next(reader)]
14961497
print(tabulate(reader, headers))
14971498
```
@@ -1527,8 +1528,10 @@ Image
15271528
# $ pip3 install pillow
15281529
from PIL import Image
15291530
width, height = 100, 100
1530-
img = Image.new('L', (width, height), 'white')
1531-
img.putdata([255 * a/(width*height) for a in range(width*height)])
1531+
img = Image.new('L', (width, height), 'white')
1532+
size = width * height
1533+
pixels = [255 * a/size for a in range(size)]
1534+
img.putdata(pixels)
15321535
img.save('out.png')
15331536
```
15341537

@@ -1639,9 +1642,10 @@ def odds_handler(sport):
16391642
```python
16401643
# $ pip3 install requests
16411644
>>> import requests
1642-
>>> url = 'http://localhost:8080/odds/football'
1643-
>>> r = requests.post(url, data={'team': 'arsenal f.c.'})
1644-
>>> r.json()
1645+
>>> url = 'http://localhost:8080/odds/football'
1646+
>>> data = {'team': 'arsenal f.c.'}
1647+
>>> response = requests.post(url, data=data)
1648+
>>> response.json()
16451649
['arsenal f.c.', 2.44, 3.29]
16461650
```
16471651

@@ -1698,11 +1702,11 @@ Line # Hits Time Per Hit % Time Line Contents
16981702
```python
16991703
# $ pip3 install pycallgraph
17001704
from pycallgraph import output, PyCallGraph
1701-
from datetime import datetime
1702-
graph = output.GraphvizOutput()
1705+
from datetime import datetime
17031706
time_str = datetime.now().strftime('%Y%m%d%H%M%S')
1704-
graph.output_file = f'profile-{time_str}.png'
1705-
with PyCallGraph(output=graph):
1707+
filename = f'profile-{time_str}.png'
1708+
drawer = output.GraphvizOutput(output_file=filename)
1709+
with PyCallGraph(output=drawer):
17061710
<code_to_be_profiled>
17071711
```
17081712

0 commit comments

Comments
 (0)