ScoDoc-PE/scotests/demo/gen_nomprenoms.py

29 lines
918 B
Python
Raw Normal View History

2020-10-21 00:22:25 +02:00
# -*- coding: utf-8 -*-
import os
import random
from pathlib import Path
cur_dir = Path(os.path.abspath(__file__)).parent
# Noms et prénoms les plus fréquents en France:
NOMS = [x.strip() for x in open(cur_dir / "noms.txt").readlines()]
PRENOMS_H = [x.strip() for x in open(cur_dir / "prenoms-h.txt").readlines()]
PRENOMS_F = [x.strip() for x in open(cur_dir / "prenoms-f.txt").readlines()]
PRENOMS_X = [x.strip() for x in open(cur_dir / "prenoms-x.txt").readlines()]
2020-10-21 00:22:25 +02:00
def nomprenom(civilite):
"""Un nom et un prenom au hasard,
toujours en majuscules. Pour tests et démos.
2020-11-11 22:05:29 +01:00
"""
if civilite == "F":
2020-10-21 00:22:25 +02:00
prenom = random.choice(PRENOMS_F)
elif civilite == "M":
2020-10-21 00:22:25 +02:00
prenom = random.choice(PRENOMS_H)
elif civilite == "X":
prenom = random.choice(PRENOMS_X)
else:
raise ValueError("civilite must be M, F or X")
2020-11-11 22:05:29 +01:00
return random.choice(NOMS).upper(), prenom.upper()