Modifications

Sauter à la navigation Sauter à la recherche
386 octets ajoutés ,  11 novembre 2016 à 11:52
Ligne 30 : Ligne 30 :  
</syntaxhighlight>
 
</syntaxhighlight>
   −
{{traduction}}
+
Vous devriez voir l'appel a la fonction {{fname|add()}} (ajouter) et le resultat 1 + 1 retourné. Si vous voyez un {{fname|ImportError}} indiquant le module test ne peut pas être chargé alors assurez vous que vous exécutez Python depuis le même répertoire que votre fichier test.py.
   −
You should see the add function called and the result of 1 + 1 returned.  If you see an {{fname|ImportError}} that the test module can't be found make sure you're running Python from the same directory as test.py is located.
+
Essayez ensuite d'appeler la fonction {{fname|subtract()}} (soustraction) comme nous l'avons fait pour l'addition. Rappelez vous bien d'ajouter le nom du module devant le nom de la fonction que vous voulez appeler!
 
  −
Try calling the subtract function just like the add function was called.  Remember you need to add the module name in front of the function when you call it!
      
{{ADFImage|FEATHER-CHARGER-MODULE-IMPORT-10.png}}
 
{{ADFImage|FEATHER-CHARGER-MODULE-IMPORT-10.png}}
   −
Now that you see how a simple .py file import works on your computer try doing the same with MicroPython. Copy the test.py file to the root of your board's filesystem. For example if you're using a tool like ampy to copy files you would run something like:
+
Maintenant que vous savez comment importer un simple fichier .py sur votre ordinateur, nous allons faire la même chise avec notre carte MicroPython. Copiez le fichier test.py dans le répertoire racine (''root'') de votre système de fichier. Par exemple, si vous utilisez un outil tel que {{fname|ampy}} pour copier les fichiers que vous désirez exécuter alors vous devriez utiliser une syntaxe similaire à celle-ci:
    
  <nowiki>ampy --port /board/serial/port put test.py</nowiki>
 
  <nowiki>ampy --port /board/serial/port put test.py</nowiki>
   −
Then connect to the board's REPL and run the same Python code to import and use the module:
+
Connectez vous ensuite en REPL sur la carte et exécutez les mêmes instructions Python (que celles ci-dessus) pour importer et utiliser le module:
 
      
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
Ligne 53 : Ligne 50 :  
{{ADFImage|FEATHER-CHARGER-MODULE-IMPORT-11.png}}
 
{{ADFImage|FEATHER-CHARGER-MODULE-IMPORT-11.png}}
   −
You should see the functions run just like they did on your computer!  If you see an ImportError double check you copied the test.py file to the root of the board's filesystem and try again.
+
Vous devriez voir les fonctions fonctionner comme elles le font You should see the functions run just like they did on your computer!  If you see an ImportError double check you copied the test.py file to the root of the board's filesystem and try again.
    
Importing and using code from a .py file in MicroPython is as easy as copying the file to the board and importing to use as above.  Remember the file needs to be in the same location as the script which is importing and using it.  In most cases your scripts will be in the root of the board's filesystem so that's usually where you want to place .py files which will be imported.
 
Importing and using code from a .py file in MicroPython is as easy as copying the file to the board and importing to use as above.  Remember the file needs to be in the same location as the script which is importing and using it.  In most cases your scripts will be in the root of the board's filesystem so that's usually where you want to place .py files which will be imported.
29 918

modifications

Menu de navigation