Modifications

Sauter à la navigation Sauter à la recherche
770 octets ajoutés ,  10 novembre 2016 à 20:14
Ligne 137 : Ligne 137 :  
{{ADFImage|FEATHER-CHARGER-MODULE-IMPORT-21.png}}
 
{{ADFImage|FEATHER-CHARGER-MODULE-IMPORT-21.png}}
    +
Connect to the board's REPL and try importing the test package and using its functions as before:
 +
 +
<syntaxhighlight lang="python">
 +
import test
 +
test.add(1, 1)
 +
test.subtract(1, 1)
 +
</syntaxhighlight>
 +
 +
{{ADFImage|FEATHER-CHARGER-MODULE-IMPORT-22.png}}
 +
 +
You should see the package import and the functions work exactly as before when they were in a single test.py file!
 +
 +
Breaking a complex module apart into multiple files with a package is a great way to simplify and structure code.  In this simple example it seems like a bit of unnecessary work, but as scripts get more complex and re-use common code it will help immensely to break them into modules and packages.  You can even start to share code with others by giving them your modules and packages to load and use!
    
{{FEATHER-CHARGER-MODULE-TRAILER}}
 
{{FEATHER-CHARGER-MODULE-TRAILER}}
29 918

modifications

Menu de navigation