Conception — Python
Thumbnail Logo

Python is an Open Source scripting language widely used in the world of scientific and numerical computing for its power and simplicity.

The third-party packages and libraries available with Python are numerous and cover all areas of an information system (network, databases, time series, noSQL, etc.).

Python - Understanding args, kwargs in functions January 10th, 2021
Thumbnail LogoBeginning in Python, we encounter code examples with the syntaxes *args, **kwargs in function arguments. Used to other languages : what’s that ? pointers in Python ? *args and **kwargs allow multiple arguments and named arguments to be passed to a function. Nothing really rocket science. In this article, *args and **kwargs explained through simple examples, and at the same time, a quick word about the unpacking operators * and **.
Python - Practical Handbook, Quick reference guide January 7th, 2021
Thumbnail LogoA Python cheat sheet on some packages, quick reference guide to be completed over time :
  • Handling JSON data
  • Programs arguments (argparse)
  • INI files (configparser), YAML files (PyYAML)
  • HTTP requests (packages requests and httplib2) …
Python, application configuration - environment variables, ini and YAML files April 24th, 2020
Thumbnail LogoObviously, no hard-coded application configuration in programs, Python programs or not. How to read (write) configuration data with Python from environment variables, INI files or YAML files? The os, configparser and PyYAML packages meet these needs. configparser for INI files and yaml for YAML files have their advantages and inconvenients if we venture to compare these 2 packages to make a choice. The JSON format is not discussed here, a dedicated article is published on this topic.
Python, handling dictionaries with dot notation April 20th, 2020
Thumbnail LogoPython is not Javascript. Habits, hard to remove them. How to use dot notation with Python for dictionaries ? It can be achieved natively using a class or SimpleNamespace but when dictionaries are nested, it becomes tedious without developing its own library. Python community packages exist to do the job : Prodict, python-box.
Python, Managing HTTP requests with the packages requests and httplib2 April 17th, 2020
Thumbnail LogoHTTP requests with the GET or POST method are widely used when exchanging data through programming API. With Python, 2 interesting packages for executing HTTP requests: requests and httplib2. The requests package is the easiest syntactically and natively includes a JSON decoder. About the httplib2 package, a very interesting feature: a caching mechanism to avoid unnecessary network calls in some application contexts using relatively static data.
Python, Parsing arguments with the packages argparse and getopt April 15th, 2020
Thumbnail Logo2 native packages are available with Python to efficiently manage the command lines and arguments of a Python program: argparse and getopt. argparse is by far the most advanced package and offers the most productivity, about getopt a very strong resemblance to its habits when handling arguments in shell or in C language.
Python, Reading and writing JSON with the package json April 13th, 2020
Thumbnail LogoFirst things to know when learning the Python language in the current technological context (data exchange, API…): how to read and write JSON data in a Python program ? Python integrates the json package natively for these operations with the load, loads, dump and dumps methods. Coming from the Javascript programming world, some habits handling Json data are not usable directly in Python (dot notation…).
Python - Understanding and demistifying virtualenv January 24th, 2020
Thumbnail LogoWith Python, when installing a product, many dependencies can also be installed. It becomes tedious to manage polluting the Python global distribution : dependencies, package versions conflicts, binaries… The packages used by the most users can be installed in the system distribution and packages needed to only one user/product in a virtual environment using virtualenv. How to create and use virtual environments with virtualenv ? How packages and versions are managed in virtual and system distributions ?
No more articles in English. Below, the available articles but in french.
Migration automatisée d’un site Web (HTML, PHP, CSS, JS…) de l’encodage ISO-8859-1 vers l’Unicode UTF-8 avec Python 3 September 22nd, 2016
Thumbnail LogoUn site Web en entier (fichiers html, php, css, javascript…) à migrer de l’encodage Latin 1 / ISO-8859-1 vers l’Unicode UTF-8 car au fil de l’évolution des technologies (PHP 5.4 et versions supérieures, services de partage AddThis…), des incompatibilités surgissent. Mais comment automatiser celle-ci quand plus de 500 fichiers sont concernés ? Le langage Python et son package io sont capables en quelques lignes d’automatiser la migration d’un site en entier vers UTF-8, programme python qui est proposé dans cet article. Le package chardet de Python est bien capable de détecter les encodages de fichiers toutefois il est plus fiable d’utiliser la commande file et de donner ses résultats au programme Python en charge de la migration. Dans un environnement Windows de développement, aucun souci pour utiliser la commande file, la plateforme légère MinGW (Minimalist GNU for Windows) propose tous les utilitaires indispensables dont l’utilitaire file. Après la migration des fichiers, quelques opérations post migration sont nécessaires, comme le remplacement dans les balises meta des pages HTML de l’encodage ISO-8859-1 par UTF-8, ce qui peut être également automatisé par un script shell sous MingW. La modification de l’encodage vers UTF-8 doit éventuellement être réalisée au niveau global pour PHP et les connexions aux bases de données (MySQL dans ce cas pratique).