proofreading
This commit is contained in:
parent
9c124ed08e
commit
3c2f39b7c7
|
@ -28,7 +28,6 @@ Notes:
|
|||
- un nombre entier, #obvious, c'est géré par Python
|
||||
- ouvrir une parenthèse si nécessaire, avec 6 ** 6 ** 6
|
||||
- un float, en les faisant hésiter vu qu'ils sont « gérés par le CPU »
|
||||
- ouvrir une parenthèse si nécessaire avec http:// .1 + .2
|
||||
- une fonction
|
||||
- une classe (et une instance)
|
||||
- range !
|
||||
|
@ -192,7 +191,7 @@ vérifications (que l'itérateur renvoyé soit bien un itérateur).
|
|||
... def __getitem__(self, i):
|
||||
... return i
|
||||
...
|
||||
>>> i = iter(A())
|
||||
>>> i = iter(Counter())
|
||||
>>> i
|
||||
<iterator object at ...>
|
||||
>>> next(i)
|
||||
|
@ -294,6 +293,7 @@ class Counter:
|
|||
6 7
|
||||
```
|
||||
|
||||
|
||||
## On recommence
|
||||
|
||||
Notes:
|
||||
|
@ -301,6 +301,15 @@ Notes:
|
|||
Cette fois avec un itérateur dédié.
|
||||
|
||||
|
||||
## Solution
|
||||
|
||||
```python
|
||||
class BetterCounter:
|
||||
def __iter__(self):
|
||||
return CounterIterator()
|
||||
```
|
||||
|
||||
|
||||
## Solution
|
||||
|
||||
```python
|
||||
|
@ -311,15 +320,22 @@ class CounterIterator:
|
|||
def __next__(self):
|
||||
self.i += 1
|
||||
return self.i
|
||||
```
|
||||
|
||||
class Counter:
|
||||
def __iter__(self):
|
||||
return CounterIterator()
|
||||
|
||||
c = Counter()
|
||||
for i, j in zip(c, c):
|
||||
if i > 5: break
|
||||
print(i, j)
|
||||
## Solution
|
||||
|
||||
```python
|
||||
>>> c = BetterCounter()
|
||||
>>> for i, j in zip(c, c):
|
||||
... if i > 5: break
|
||||
... print(i, j)
|
||||
0 0
|
||||
1 1
|
||||
2 2
|
||||
3 3
|
||||
4 4
|
||||
5 5
|
||||
```
|
||||
|
||||
Notes:
|
||||
|
@ -338,7 +354,7 @@ itérables.
|
|||
|
||||
Attention, une fonction générateur renvoie un itérateur, (qu'on
|
||||
appelle un générateur), pas un itérable ! Et là on est bien contents
|
||||
qu'un itérateur ai un __iter__ qui se renvoie lui même, pour pouvoir
|
||||
qu'un itérateur ai un `__iter__` qui se renvoie lui même, pour pouvoir
|
||||
l'utiliser dans un for !
|
||||
|
||||
|
||||
|
@ -355,7 +371,7 @@ Oui.
|
|||
## Exemple
|
||||
|
||||
```python
|
||||
class Counter:
|
||||
class GenCounter:
|
||||
def __iter__(self):
|
||||
i = 0
|
||||
while True:
|
||||
|
@ -381,13 +397,14 @@ Il ne s'exécute que si le `for` sort sans `break`.
|
|||
## `else`
|
||||
|
||||
```python
|
||||
n = 13
|
||||
for i in range(2, n - 1):
|
||||
if n % i == 0:
|
||||
print(f"{n} is not prime")
|
||||
break
|
||||
else:
|
||||
print(f"{n} is prime")
|
||||
>>> n = 13
|
||||
>>> for i in range(2, n - 1):
|
||||
... if n % i == 0:
|
||||
... print(f"{n} is not prime")
|
||||
... break
|
||||
... else:
|
||||
... print(f"{n} is prime")
|
||||
13 is prime
|
||||
```
|
||||
|
||||
Notes:
|
||||
|
@ -405,7 +422,7 @@ Ah j'ai utilisé une f-string.
|
|||
|
||||
```python
|
||||
>>> f"{42:08b}"
|
||||
00101010
|
||||
'00101010'
|
||||
```
|
||||
|
||||
Notes:
|
||||
|
@ -439,7 +456,12 @@ Notes:
|
|||
|
||||
Pour se remémorer ces choses, cherchez les PEPs, typiquement la 448, la 3132, ...
|
||||
|
||||
Parler de `deep unpacking`.
|
||||
- Parler de `deep unpacking`.
|
||||
- Parler de `head, *rest`, ...
|
||||
|
||||
|
||||
## Ça peut rappeler *args et **kwargs
|
||||
## Ça peut rappeler `*args` et `**kwargs`
|
||||
|
||||
Notes:
|
||||
|
||||
Démo si nécessaire.
|
||||
|
|
|
@ -10,11 +10,20 @@
|
|||
|
||||
## La MRO
|
||||
|
||||
Notes:
|
||||
|
||||
Simple démo REPL : `bool.__mro__`.
|
||||
|
||||
## `super()` !
|
||||
|
||||
Notes:
|
||||
|
||||
Et la coopération.
|
||||
Et la coopération, démo avec deux classes : `TCPConnection` qui prend
|
||||
`host, port, timeout`, et `HTTPConnection` qui prend url, method, ...`
|
||||
|
||||
Démo aussi : passer un argument de trop et voir que object() se plains.
|
||||
|
||||
Antisèche : https://wyz.fr/3Z8
|
||||
|
||||
|
||||
## Le protocole « descripteur »
|
||||
|
|
|
@ -127,11 +127,20 @@ En initiation on apprend a les utiliser.
|
|||
En avancé on apprend à en faire.
|
||||
|
||||
|
||||
Notes:
|
||||
|
||||
Just for doctest:
|
||||
```python
|
||||
def clock(f=None, *args, **kwargs):
|
||||
return lambda *args: None
|
||||
```
|
||||
|
||||
## Les décorateurs
|
||||
|
||||
```python3
|
||||
@clock
|
||||
def fib(...
|
||||
def fib(n):
|
||||
...
|
||||
```
|
||||
|
||||
équivaut à
|
||||
|
@ -151,7 +160,8 @@ peut les empiler (clarifier l'ordre).
|
|||
|
||||
```python3
|
||||
@clock(deadline=10)
|
||||
def fib(...
|
||||
def fib(n):
|
||||
...
|
||||
```
|
||||
|
||||
équivaut à
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
```python
|
||||
>>> bytes([0x01, 0x02, 0x03]) == b"\x01\x02\x03"
|
||||
True
|
||||
```
|
||||
|
||||
Notes:
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
SRCS := $(wildcard *-*.md)
|
||||
HTML := $(addprefix output/,$(SRCS:.md=.html))
|
||||
SRCS := $(sort $(wildcard *-*.md))
|
||||
REVEAL_JS_VERSION := 3.9.2
|
||||
REVEAL_JS := output/reveal.js-$(REVEAL_JS_VERSION)/up-to-date
|
||||
|
||||
|
@ -22,25 +21,16 @@ $(REVEAL_JS):
|
|||
test:
|
||||
python test.py *.md
|
||||
|
||||
index.md: $(SRCS)
|
||||
for file in *-*.md; \
|
||||
do printf "# [%s](%s)\n\n" "$$file" "$$(printf "%s" "$$file" | sed s/.md/.html/)"; \
|
||||
grep -h '^#' "$$file" | sed 's/^# /- /;s/^## / - /'; \
|
||||
done | uniq > $@
|
||||
|
||||
index.html: index.md
|
||||
mkdir -p output
|
||||
python -m markdown -o html $< -f $@
|
||||
|
||||
.PHONY: static
|
||||
static: $(HTML) index.html
|
||||
rm -f output/index.html
|
||||
cp index.html output/index.html
|
||||
static: output/index.html
|
||||
|
||||
output/index.md: $(SRCS)
|
||||
mkdir -p output/
|
||||
cat $(SRCS) > output/index.md
|
||||
|
||||
# To discover pandoc variables: less $(dpkg -L pandoc-data | grep reveal)
|
||||
output/%.html: %.md $(REVEAL_JS)
|
||||
mkdir -p output/
|
||||
python3 ../md2reveal/md2reveal.py --revealjs-url "reveal.js-$(REVEAL_JS_VERSION)" $< $@
|
||||
output/index.html: output/index.md $(REVEAL_JS)
|
||||
python3 ../md2reveal/md2reveal.py --revealjs-url "reveal.js-$(REVEAL_JS_VERSION)" output/index.md output/index.html
|
||||
if [ -d static ]; then cp -a static output; fi
|
||||
|
||||
.PHONY: rsync
|
||||
|
@ -49,4 +39,4 @@ rsync: static
|
|||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -fr output index.md index.html
|
||||
rm -fr output
|
||||
|
|
Loading…
Reference in New Issue
Block a user