Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can see which application started Python by looking at sys.executable, which returns the executable that was used to start the Python session.

import os
import sys

def main():
    # Determine if this script is being run from PSSE or plain Python.
    full_path_executable = sys.executable
    # Remove the folder path and keep only the executable file (in lower case).
    executable = os.path.basename(full_path_exec).lower()

    run_in_psse = True
    if executable in ['python.exe', 'pythonw.exe']:
        # If the executable was one of the above, it is a Python session.
        run_in_psse = False        

    if not run_in_psse:
        psspy.stop_2()
    else:
        # do something else to finish up.
click to hide/show revision 2
wrong variable names

You can see which application started Python by looking at sys.executable, which returns the executable that was used to start the Python session.

import os
import sys

def main():
    # Determine if this script is being run from PSSE or plain Python.
    full_path_executable = sys.executable
    # Remove the folder path and keep only the executable file (in lower case).
    executable = os.path.basename(full_path_exec).lower()
os.path.basename(full_path_executable).lower()

    run_in_psse = True
    if executable in ['python.exe', 'pythonw.exe']:
        # If the executable was one of the above, it is a Python session.
        run_in_psse = False        

    if not run_in_psse:
        psspy.stop_2()
    else:
        # do something else to finish up.