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?

0

Your Answer

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.