Scripting
Entête de script Python
En général, l'entête d'un script Python doit comporter :
- la version de Python utilisée;
- l'encodage du fichier.
Exemple d'entête pour un script Python 3
1 2 |
|
Exemple d'entête pour un script Python 2
1 2 |
|
Attention
La déclaration #!/usr/bin/env python
est ambiguë. En effet elle peut faire référence à Python 2.x ou Python 3.x en fonction des versions de Python installées sur le système.
Ressources
- PEP 263 -- Defining Python Source Code Encodings | Python.org
- PEP 394 -- The "python" Command on Unix-Like Systems | Python.org
- shell - Should I put #! (shebang) in Python scripts, and what form should it take? - Stack Overflow
Environnement d'exécution principal
1 2 3 |
|
Ressources
Script simple
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Script simple avec arguments
sys.argv
permet de récupérer la liste des arguments de la ligne de commande passés à un script Python.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Command Line Interfaces (CLIs)
- Click is a Python package for creating beautiful command line interfaces in a composable way with as little code as necessary.
- Python Fire is a library for automatically generating command line interfaces (CLIs) from absolutely any Python object.
Dernière mise à jour:
May 6, 2022