Modules & standard library
Python ↔ Baobab
11 correspondences
importer/depuis translate import/from. The standard library frenchifies the essential modules: maths for math, aleatoire for random.
| Python | Baobab | Description |
|---|---|---|
| import math | importer maths | Import the math module. |
| from math import sqrt | importer racine depuis maths | Import a single function from a module. |
| math.sqrt(x) | maths.racine(x) | Square root. |
| math.pi | maths.pi | The constant π. |
| math.floor(x) / math.ceil(x) | maths.plancher(x) / maths.plafond(x) | Round down / up to the nearest integer. |
| import random | importer aleatoire | Import the randomness module. |
| random.randint(a, b) | aleatoire.entier(a, b) | Random integer between a and b inclusive. |
| random.choice(l) | aleatoire.choix(l) | Random element from a list. |
| random.shuffle(l) | aleatoire.melanger(l) | Shuffle a list in place. |
| random.random() | aleatoire.nombre() | Random float between 0 and 1. |
| import utils (fichier local) | importer utils depuis "./utils.bao" | Import a module from your project. |
Complete example — Baobab ↔ Python
Baobab
1234567891011121314151617181920importer maths
importer aleatoire
afficher(maths.racine(144)) # → 12.0
afficher(maths.pi) # → 3.141592653589793
afficher(maths.plancher(3.9)) # → 3
afficher(maths.plafond(3.1)) # → 4
tirage = aleatoire.entier(1, 6)
afficher(f"Le dé donne {tirage}")
equipe = ["Amina", "Kofi", "Fatou"]
capitaine = aleatoire.choix(equipe)
aleatoire.melanger(equipe)
afficher(f"Capitaine : {capitaine}")
afficher(f"Ordre de passage : {equipe}")
# Module local du projet
importer utils depuis "./utils.bao"
afficher(utils.additionner(2, 3))Python
1234567891011121314151617181920import math
import random
print(math.sqrt(144)) # → 12.0
print(math.pi) # → 3.141592653589793
print(math.floor(3.9)) # → 3
print(math.ceil(3.1)) # → 4
tirage = random.randint(1, 6)
print(f"Le dé donne {tirage}")
equipe = ["Amina", "Kofi", "Fatou"]
capitaine = random.choice(equipe)
random.shuffle(equipe)
print(f"Capitaine : {capitaine}")
print(f"Ordre de passage : {equipe}")
# Local project module
import utils
print(utils.additionner(2, 3))