Unfortunately, I discovered a problem in the mBlock Python editor that I even think is a BUG.
I think that a major goal in STEM education is modularization as well as reusability of CODE blocks.
In my programming experience, I have regularly created collections of smaller helper functions.
This is also supported by Python via the import function. In mBlock Python, however, this unfortunately does not work (unlike in other Python IDEs - e.g. PyCharm).
I would like to demonstrate this with the following example:
Starting point is the following demonstration program:
generated by mBlock5 for CyberPi
codes make you happy
import event, time, cyberpi
@event.start
def on_start():
“”“In this Program the module is called directly”""
Salutation_N_S(1, ‘Miller’)
Salutation_N_S(0, ‘’)
Salutation_N_S(2, ‘Smith’)
I want to outsource the module “Salutation_N_S” to an external file.
Therefore I have created a file Tools.py in the same directory, which contains only this module.
If I then delete these lines in the main program and instead enter the line from Tools.py IMPORT Salutation_N_S, it looks like this:
No error message is displayed by the editor.
If I then comment out the line from Tools.py IMPORT Salutation_N_S, the calls to the function are displayed as errors:
Cross check:
I copy the source for the module additionally into the main program. Then this is recognized as a double definition.
So Python has recognized the IMPORT function correctly.
If I then start this program in live mode, an error message is displayed on the screen of the mBot.
If I switch to upload mode the following message is displayed in the editor:
Hope, You can see the problem or can say, what I can do.
phg
Translated with www.DeepL.com/Translator (free version)