Skip to content

Commit d5bae65

Browse files
committed
parse-people: smoother execution
1 parent 3b89203 commit d5bae65

File tree

6 files changed

+12
-11
lines changed

6 files changed

+12
-11
lines changed

notebooks/tps/parse-people/.teacher/README-parse-people-corrige-nb.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def parse(filename):
6666
result.append((first, last, email, phone))
6767
return result
6868
69-
L = parse("data-simple-03"); L
69+
L = parse("data/people-simple-03.txt"); L
7070
```
7171

7272
```{code-cell} ipython3
@@ -83,7 +83,7 @@ def parse_bis(filename):
8383
result.append(line.strip().split())
8484
return result
8585
86-
parse_bis("data-simple-03")
86+
parse_bis("data/people-simple-03.txt")
8787
```
8888

8989
```{code-cell} ipython3
@@ -97,7 +97,7 @@ def parse_ter(filename):
9797
with open(filename, encoding="utf-8") as f:
9898
return [line.strip().split() for line in f]
9999
100-
parse_ter("data-simple-03")
100+
parse_ter("data/people-simple-03.txt")
101101
```
102102

103103
````{admonition} discussion
@@ -311,7 +311,7 @@ def group_parse(filename):
311311
groups_by_name[group].add(person)
312312
return persons, groups_by_name
313313
314-
G = group_parse("data-groups-10"); G
314+
G = group_parse("data/people-groups-10.txt"); G
315315
```
316316

317317
```{code-cell} ipython3
@@ -324,7 +324,7 @@ def group_parse_bis(filename) -> tuple[
324324
]:
325325
return group_parse(filename)
326326
327-
group_parse_bis("data-groups-10")
327+
group_parse_bis("data/people-groups-10.txt")
328328
```
329329

330330
## regexps (optional)
@@ -367,25 +367,25 @@ def _check_values(L, re_n, re_e, re_p):
367367

368368
```{code-cell} ipython3
369369
# first rough approx.
370-
re_names = re.compile("^[-_a-zA-Z]+$")
371-
re_email = re.compile("^[-a-zA-Z0-9.]+@[-a-zA-Z0-9.]+$")
370+
re_names = re.compile(r"^[-_a-zA-Z]+$")
371+
re_email = re.compile(r"^[-a-zA-Z0-9.]+@[-a-zA-Z0-9.]+$")
372372
# we need to escape the + because otherwise it means repetition
373-
re_phone = re.compile("^(0|\+33)[0-9]{9}$")
373+
re_phone = re.compile(r"^(0|\+33)[0-9]{9}$")
374374
375375
376376
def check_values(L: list) -> None:
377377
return _check_values(L, re_names, re_email, re_phone)
378378
379-
L120 = group_parse("data-groups-120")[0]
379+
L120 = group_parse("data/people-groups-120.txt")[0]
380380
check_values(L120)
381381
```
382382

383383
```{code-cell} ipython3
384384
# using \w is tempting, but it will allow for _
385385
# and we dont want that...
386386
387-
re_names_bis = re.compile("^[-_\w]+$")
388-
re_email_bis = re.compile("^[-\w0-9.]+@[-\w0-9.]+$")
387+
re_names_bis = re.compile(r"^[-_\w]+$")
388+
re_email_bis = re.compile(r"^[-\w0-9.]+@[-\w0-9.]+$")
389389
390390
def check_values_bis(L: list) -> None:
391391
return _check_values(L, re_names_bis, re_email_bis, re_phone)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../data
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)