pybricks / support

Pybricks support and general discussion
MIT License
104 stars 6 forks source link

[Feature] Python code snippet within blocks #1586

Open southlakefll opened 3 months ago

southlakefll commented 3 months ago

I think I nice future feature would be to have a "python snippet" block. That would allow running of small sections of python code within a block. This would create an intermediate step for kids to do a little python without leaving the blocks environment.

This is a feature that is available in the M5Stack series of microcontrollers in their block coding environment Here is a screenshot of what it looks like in their software: Screenshot 2024-04-05 151804

and the python code that is generated: image

laurensvalk commented 3 months ago

Thanks for opening this topic.

Did you know you can combine blocks and Python? Here is an example. Let's say you have a few useful Python functions you wrote:

image

You can use them in your programs like this:

image


Making something directly inline might be easier for the occasional oneliner, but doing it in a Python file can also be a good learning experience and might be easier in the long run, since you have a proper editor with syntax highlighting and so on.

This can also be a nice way for teams to grow a library with useful functions over the years, which new team members can use with ease.