Can argument vectors be passed to a program in Thonny?

3,325 views
Skip to first unread message

Scott Webster

unread,
Jun 8, 2018, 1:43:44 AM6/8/18
to thonny
I poked around a bit in the settings but wasn't able to see any way of supplying an argument vector to a python script to be run and debugged in Thonny.  I guess maybe that's going a little too far beyond beginner.

Aivar Annamaa

unread,
Jun 8, 2018, 1:53:27 AM6/8/18
to thonny
Hi Scott!

At the moment you can pass arguments in the shell. When you simply hit F5, Thonny sends something like `%Run my_script.py` to the Shell. In order to pass arguments, you need to manually write something like  `%Run my_script.py arg1 arg2` (you can also use arrow up to get previous run command and then add the arguments).

Do you think it's important to have a means for fixing the arguments such that they are applied on each subsequent F5? Or maybe something more general, where you can define your own command line (or maybe a macro with placeholders) to a shortcut key? This could be useful for running custom tools (eg. `!pylint my_script.py`).

best regards,
Aivar

Scott Webster

unread,
Jun 8, 2018, 10:17:59 AM6/8/18
to thonny
Aha!  I had tried that but didn't think it had worked, but now I realize that I was confused by the message the script returned.  I was wanting to step through the execution of uflash to watch what it is doing as it converts a python file to a hex file for the microbit.  So I first attempted simply running uflash.py with a microbit script.

With no command line arguments, uflash just flashes the MicroPython interpreter to the microbit.  But it always reports "Flashing Python to: /run/media/scott/MICROBIT/micropython.hex" which gives the impression that it is only flashing the interpreter and made me think that it had ignored the argument.

Scott Webster

unread,
Jun 8, 2018, 11:38:52 AM6/8/18
to thonny
I think having a more obvious (visible in the menus) method for executing and debugging a script with arguments would be beneficial.  The question will always be how to add features without adding undue complexity.  There could be a way to add script arguments and a separate way to toggle the use of the arguments on or off.


On Friday, June 8, 2018 at 1:53:27 AM UTC-4, Aivar Annamaa wrote:

Scott Webster

unread,
Jun 8, 2018, 11:47:37 AM6/8/18
to thonny
Maybe there could be a separate GUI element (listed and toggleable in the View menu) that would include a text box for typing in the argument list as well as checkboxes for "Use with Run" and Use with Debug".

Aivar Annamaa

unread,
Jun 20, 2018, 10:33:18 PM6/20/18
to tho...@googlegroups.com

Hi!

I implemented it almost as you suggested (without the checkboxes though):

The feature will be in the next beta.

Do you think the checkboxes are important?

best regards,
Aivar

--
You received this message because you are subscribed to the Google Groups "thonny" group.
To unsubscribe from this group and stop receiving emails from it, send an email to thonny+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/thonny/a08c82d1-b0ea-4a12-abf3-4aaf1ec63c2e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Scott Webster

unread,
Jun 21, 2018, 11:02:22 AM6/21/18
to thonny
Hi Aivar,

Thanks for adding that feature.

My thinking regarding the checkboxes was that it might be a good convenience feature to be able to turn the use of the argument on and off without having to delete and retype the text.  Of course, clever users could come up with workarounds like opening a text editor to create a list of argument strings to copy and paste into the text box.  I still think that having some intuitive method for turning the use of the argument on and off would be good.  It wouldn't have to be separated into 'run' and 'debug'.  Having the text in the text box go from dark to grey would also help the user recognize that it is turning on and off.

By the way, I've been hacking ntoll's uflash to add features suitable for generating .hex files on the local filesystem for later copying to a microbit.  

Aivar Annamaa

unread,
Jun 21, 2018, 2:00:12 PM6/21/18
to tho...@googlegroups.com
21.06.2018 18:02 Scott Webster kirjutas:
> My thinking regarding the checkboxes was that it might be a good
> convenience feature to be able to turn the use of the argument on and
> off without having to delete and retype the text

I now replaced the arguments Entry with a Combobox which remembers 10
last used argument strings. I suppose this will also cover your
requirements.

best regards,
Aivar
Reply all
Reply to author
Forward
0 new messages