Modifications

Sauter à la navigation Sauter à la recherche
156 octets ajoutés ,  11 novembre 2016 à 12:55
Ligne 101 : Ligne 101 :  
{{traduction}}
 
{{traduction}}
   −
'''Be sure to call this file exactly __init__.py'''!  Python looks for this file name to know that it found a package. If you don't have this file or if it's not named correctly then Python will fail to import the package!
+
'''Soyez attentif, le fichier doit exactement s'appeler __init__.py'''!  Python recherche ce nom de fichier pour savoir s'il s'agit d'un paquet/package. Si vous n'avez pas ce fichier ou s'il nest pas nommé correctement alors Python n'importera pas le paquet!
   −
The code inside '''__init__.py''' runs when the package is imported in a script. You can see this code imports the add function from the '''add.py''' script in the package, and the subtract function from the '''subtract.py''' script.
+
Le code à l'intérieur du fichier '''__init__.py''' est exécuté lorsque le paquet/package est importé par un script. Vous pouvez voir dans le code de __init__.py qu'il importe la fonction {{fname|add}} depuis le fichier '''add.py''' (contenu dans le paquet/package) ainsi que la fonction {{fname|substract}} contenu dans le fichier '''subtract.py'''.
    
Notice the import statements refer to '''add.py''' by its full 'absolute import' name of '''test.add'''.  The test. in front of add is the package name, i.e. the name of the package directory.  You can't run a command like "'''from add import add'''" in the __init__.py since Python would get confused if it should load an add.py from inside the module or from elsewhere.  Using the full name '''test.add''' tells Python to use the '''add.py''' module inside the '''test''' package directory.
 
Notice the import statements refer to '''add.py''' by its full 'absolute import' name of '''test.add'''.  The test. in front of add is the package name, i.e. the name of the package directory.  You can't run a command like "'''from add import add'''" in the __init__.py since Python would get confused if it should load an add.py from inside the module or from elsewhere.  Using the full name '''test.add''' tells Python to use the '''add.py''' module inside the '''test''' package directory.
29 918

modifications

Menu de navigation