0

We have a module that is really useful to run interactively as a commandline script.

python -i tool

All users are python coders. So while there has been talk of making an interactive commandline app, the power of just being able to use the tool with code nobody wants to abandon, and it would be too much to recode that kind of power, unless there is something obvious.

Literally the only annoyance is having to type

python -i tool

Because everyone types

./tool

gets an unhelpful message and remembers.

I was going to improve the message. But I wondered if I could just make it work. When the script is run can it run itself with -i. If the script is a different name from the module, it can be a shell script. But the same file? Can I run python interactively just from the

if __name__ == "__main__":

bit?

Ian
  • 3,619
  • 1
  • 21
  • 32
  • 1
    would adding `subprocess.run("python -i tool")` in the program body solve your issue? It isn't exactly clear what you're saying here, but [`subprocess.run`](https://docs.python.org/3/library/subprocess.html#.run) allows you to run shell commands from inside a python program. Don't forget to put in `import os` in the intro, to allow for use of the `subprocess` module. – Math chiller May 24 '20 at 22:50
  • 2
    @Mathchiller: If you want to import `subprocess`, that's `import subprocess`, not `import os`. Anyway, there's a better way (see dupe target). – user2357112 May 24 '20 at 22:55
  • @user2357112supportsMonica Thanks for the dupe. Exactly right. It didn't suggest. My search foo is weak. – Ian May 24 '20 at 23:01

0 Answers0