IMPORT not Working in Python


#1

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:

grafik

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:

grafik

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:

grafik

Hope, You can see the problem or can say, what I can do.

phg

Translated with www.DeepL.com/Translator (free version)


#2

Hi phg1

Sorry for the late reply,we still can’t figure out the problem,and we have posted the problem in our group last week but up to now,we still can’t fix this problem,and thank you for your feedback we’ll send it to our algorithm engineer to fix this bug

Yours


#3

Hi phg1

Our algorithm engineer indicates it might be a problem of capitalization and please check the file name of tools.py whether it starts with capital letters or not


#4

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.