sync with O'Reilly Atlas

This commit is contained in:
Luciano Ramalho
2021-06-26 13:42:28 -03:00
parent e986e3bdc0
commit f0f160844d
26 changed files with 308 additions and 1004 deletions

View File

@@ -9,12 +9,8 @@ def clock(func):
result = func(*args, **kwargs)
elapsed = time.perf_counter() - t0
name = func.__name__
arg_lst = []
if args:
arg_lst.append(', '.join(repr(arg) for arg in args))
if kwargs:
pairs = [f'{k}={v!r}' for k, v in kwargs.items()]
arg_lst.append(', '.join(pairs))
arg_lst = [repr(arg) for arg in args]
arg_lst.extend(f'{k}={v!r}' for k, v in kwargs.items())
arg_str = ', '.join(arg_lst)
print(f'[{elapsed:0.8f}s] {name}({arg_str}) -> {result!r}')
return result

View File

@@ -8,7 +8,7 @@ from clockdeco import clock
def fibonacci(n):
if n < 2:
return n
return fibonacci(n-2) + fibonacci(n-1)
return fibonacci(n - 2) + fibonacci(n - 1)
if __name__ == '__main__':

View File

@@ -8,7 +8,7 @@ htmlize(): generic function example
>>> htmlize(abs)
'<pre>&lt;built-in function abs&gt;</pre>'
>>> htmlize('Heimlich & Co.\n- a game') # <2>
'<p>Heimlich &amp; Co.<br>\n- a game</p>'
'<p>Heimlich &amp; Co.<br/>\n- a game</p>'
>>> htmlize(42) # <3>
'<pre>42 (0x2a)</pre>'
>>> print(htmlize(['alpha', 66, {3, 2, 1}])) # <4>
@@ -45,7 +45,7 @@ def htmlize(obj: object) -> str:
@htmlize.register # <2>
def _(text: str) -> str: # <3>
content = html.escape(text).replace('\n', '<br>\n')
content = html.escape(text).replace('\n', '<br/>\n')
return f'<p>{content}</p>'
@htmlize.register # <4>