issue144:tutoriel1
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue144:tutoriel1 [2019/05/03 07:33] – créée d52fr | issue144:tutoriel1 [2019/05/08 10:27] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | First, I would like to congratulate Ronnie and the entire FCM staff for 12 years of FCM! I am honoured to be a small part of this wonderful publication. | + | **First, I would like to congratulate Ronnie and the entire FCM staff for 12 years of FCM! I am honoured to be a small part of this wonderful publication.** |
- | Now on to the meat of this month' | + | En premier lieu, je voudrais féliciter Ronnie et toute l' |
+ | |||
+ | **Now on to the meat of this month' | ||
On April 4, 2019, PEP 570 (Python Enhancement Proposal) was accepted by the Python Steering Council, which includes Guido van Rossum. While it is unknown how soon it will be able to be implemented, | On April 4, 2019, PEP 570 (Python Enhancement Proposal) was accepted by the Python Steering Council, which includes Guido van Rossum. While it is unknown how soon it will be able to be implemented, | ||
Ligne 8: | Ligne 10: | ||
and the original PEP can be found at... | and the original PEP can be found at... | ||
+ | |||
+ | https:// | ||
+ | |||
+ | Maintenant, rentrons dans le vif du sujet du mois. | ||
+ | |||
+ | Le 4 avril 2019, la PEP 570 (Python Enhancement Proposal - Proposition d' | ||
+ | |||
+ | Voici le lien vers la page officielle expliquant les modifications : https:// | ||
+ | |||
+ | et la PEP originale peut être trouvée ici... | ||
https:// | https:// | ||
- | Note: The information presented in this article is not meant to be an in-depth teaching article on Python programming using the PEP 570 syntax. It's intended to only give you a digested overview of what to expect, once it is implemented, | + | **Note: The information presented in this article is not meant to be an in-depth teaching article on Python programming using the PEP 570 syntax. It's intended to only give you a digested overview of what to expect, once it is implemented, |
- | Some background | + | Note : L' |
+ | |||
+ | **Some background | ||
Currently, Python uses what is called positional-or-keyword parameters. When we define a function, as we all know, we do it like this... | Currently, Python uses what is called positional-or-keyword parameters. When we define a function, as we all know, we do it like this... | ||
Ligne 21: | Ligne 35: | ||
... | ... | ||
- | and for the most part, that is sufficient for most purposes. However, if someone wants to design a library, the number of parameters, placement and parameter names need to stay the same from release to release. Otherwise, it will break any software that calls it. | + | and for the most part, that is sufficient for most purposes. However, if someone wants to design a library, the number of parameters, placement and parameter names need to stay the same from release to release. Otherwise, it will break any software that calls it.** |
- | The new syntax for function definitions would look like that shown above. | + | Mise en situation |
+ | |||
+ | Actuellement, | ||
+ | |||
+ | def my_function(parm1=None, | ||
+ | |||
+ | ... | ||
+ | |||
+ | et, la plupart du temps, c'est suffisant pour la majorité des besoins. Cependant, si quelqu' | ||
+ | |||
+ | **The new syntax for function definitions would look like that shown above. | ||
Here are some important notes: | Here are some important notes: | ||
Ligne 34: | Ligne 58: | ||
To show some of the ramifications of these changes, let's look at how we would access a function under the new requirements. Again, I borrowed the following lines from the PEP announcement... | To show some of the ramifications of these changes, let's look at how we would access a function under the new requirements. Again, I borrowed the following lines from the PEP announcement... | ||
- | If we have only positional_only arguments, you would use a definition like this… | + | If we have only positional_only arguments, you would use a definition like this…** |
+ | La nouvelle syntaxe pour la définition des fonctions devrait ressembler à ce qui est présenté ci-dessus. | ||
- | def my_function(p1, | + | Voici quelques points importants : |
+ | 1) Tous les paramètres après le / sont traités comme « positional-only » (à position fixe). | ||
+ | 2) Si le / n'est pas spécifié dans la définition de fonction, cette fonction n' | ||
+ | 3) La logique à propos des valeurs optionnelles pour les paramètres à position fixe reste identique à celle des paramètres « positional-or-keyword ». | ||
+ | 4) Une fois qu'un paramètre à position fixe est spécifié avec une valeur par défaut, les paramètres à position fixe ET ceux « positional-or-keyword » doivent aussi avoir des valeurs par défaut. | ||
+ | 5) Les paramètres à position fixe qui n'ont pas de valeur par défaut sont des paramètres à position fixe EXIGÉS. | ||
+ | |||
+ | Pour vous montrer quelques-unes des ramifications de ces changements, | ||
+ | |||
+ | Si vous n'avez que des arguments à position fixe, vous devriez utiliser une définition comme celle-ci : | ||
+ | |||
+ | |||
+ | **def my_function(p1, | ||
… | … | ||
Ligne 45: | Ligne 82: | ||
… | … | ||
- | However, if the parameter for “p1” has a default value, per condition #4, ‘p2’ would also need to have a default value assigned as well. So, | + | However, if the parameter for “p1” has a default value, per condition #4, ‘p2’ would also need to have a default value assigned as well. So,** |
- | def my_function(p1 = None, p2, /): | + | def my_function(p1, |
+ | … | ||
+ | |||
+ | C'est très proche de ce que nous utilisons actuellement, | ||
+ | |||
+ | def my_function(p1, | ||
+ | |||
+ | Cependant, si le paramètre « p1 » a une valeur par défaut, d' | ||
+ | |||
+ | **def my_function(p1 = None, p2, /): | ||
… | … | ||
Ligne 64: | Ligne 110: | ||
A final borrowing from the specification document is shown top right. | A final borrowing from the specification document is shown top right. | ||
- | That’s all I have this time, so I wish you a great upcoming month. | + | That’s all I have this time, so I wish you a great upcoming month. ** |
+ | |||
+ | def my_function(p1 = None, p2, /): | ||
+ | |||
+ | entraînerait une erreur de syntaxe. | ||
+ | |||
+ | def my_function(p1 = None, p2 = None, /, p_or_kw): | ||
+ | … | ||
+ | |||
+ | sera aussi invalide, car la condition n° 4 ci-dessus dit qu'une fois qu'une valeur par défaut a été définie pour un paramètre, tous les paramètres qui suivent, y compris les paramètres à position fixe ou ceux « positional-or-keyword », doivent aussi avoir une valeur par défaut. Ceci ne s' | ||
+ | |||
+ | def my_function(p1 = None, p2 = None, /, *, kw): | ||
+ | |||
+ | sera parfaitement valable et bonne. | ||
+ | |||
+ | Un dernier emprunt au document de spécification est présenté en haut à droite. | ||
+ | C'est tout ce que j'ai pour cette fois-ci et je vous souhaite un excellent mois à venir. |
issue144/tutoriel1.1556861583.txt.gz · Dernière modification : 2019/05/03 07:33 de d52fr