1

I am designing a context menu, in which I use a context menu to redirect to my python script.

Among multiple other options, one option is to launch interactive shell from the script with pre-import commands.

Here is what I have tried so far:

  1. Created Script which imports the pre-requisites start-script.py consists like below:
import os
import sys
MY_MODULE_PATH = "<path/to/my/module>"
sys.path.append("MY_MODULE_PATH")
# follows the imports from module
# ...
# ...
  1. Code-block handling to invoke script to launch as startup
 import subprocess
 startup_script = os.path.join(os.path.dirname(os.path.abspath(__file__)), "start-script.py")
 cmd = [sys.executable, "-i", startup_script]
 subprocess.check_call(cmd)

Is this is the only way or more better and simple approach then these 2 steps and files?

asked Sep 9, 2021 at 18:29

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.