Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

How to get rid of some unnecessary code when I use pythonGenerator to convert block to python code?

40 views
Skip to first unread message

ziyang

unread,
Apr 21, 2025, 11:30:37 AMApr 21
to Blockly
Hello!
    when I use a variable block in a 'controls_for' block, the output code got something wrong and unnecessary.
20250421-161655.jpg
screenshot-20250421-161738.png
i don't want to show this code in my editor, is there any option or method that i can output a simple code like:
n = 6
for i in range(n):
  print(i)

Thanks!

feni...@google.com

unread,
Apr 23, 2025, 11:44:13 AMApr 23
to Blockly
Hello,

You can either use the simpler `controls_repeat_ext` block and update i manually, or you can make a custom block and python generator to represent "for i in range". 

Other people on this mailing list may be able to chip in with block definitions, if they've done this before.


 

The block that you are using can handle more complex looping behaviour, hence the function. There isn't a simple way to just cut that behaviour out.

Hope this helps,
Rachel
Reply all
Reply to author
Forward
0 new messages