Exercices Fonctions & Modules Informations d'un module
🎉

Bravo!

Débutant 🧠 Fondamentaux 10 XP 0 personnes ont réussi

Informations d'un module

Chaque module Python possede des propriétés speciales qui te donnent des informations sur lui. Les trois principales sont :

__name__ : le nom du module
__doc__ : la documentation (docstring) du module, ou None s'il n'en a pas
__file__ : le chemin du fichier source (pas toujours present pour les modules builtin)

Ces propriétés sont accessibles comme des attributs normaux. Par exemple, math.__name__ renvoie 'math'.

Écris une fonction info_module(module) qui prend un module et renvoie un dictionnaire avec trois clés : 'nom', 'doc' et 'a_fichier'. La clé 'nom' contient le nom du module, 'doc' contient les 50 premiers caracteres de la docstring (ou 'Aucune documentation' si elle est None), et 'a_fichier' contient True ou False selon que le module a un attribut __file__ ou pas.

Exemple :
import math
info_module(math) renvoie {'nom': 'math', 'doc': 'This module provides access to the mathematical func', 'a_fichier': True}

Tests (3/4)

Nom du module math
import math
assert info_module(math)['nom'] == 'math'
Doc tronquee
import math
assert len(info_module(math)['doc']) <= 50
A un fichier
import math
assert 'a_fichier' in info_module(math)

+ 0 tests cachés

Indices (3 disponibles)

solution.py