Skip to content

Script‐ending Functions

Sam edited this page Mar 29, 2025 · 3 revisions

Success-Type Endings

End

end() is a function in Sam.py that finishes the script. It has no values, and stops the code immediately. Its most common use is at the end of all modules.

Format

There is no format, simply just call end().

Actual Function

You can find it at line 53 of Sampyhub.py.

def end():
    print("")
    print(f"{bcolors.OKGREEN}Sam.py Message: Script ended with Status Code 200 - closing Sampyhub in 5 seconds...{bcolors.ENDC}")
    time.sleep(5) 
    sys.exit(200)

Failure-Type Endings

Kill

kill(status) is a function in Sam.py that aborts the script. Its most common use is in Search, when the user doesn't want to run the script.

Format

You must provide the most relevant status code to exit with. For example, when the user rejects module running, you would use kill(499).

Actual Function

You can find it at line 43 of Sampyhub.py.

def kill(status):
    print("")
    print(f"{bcolors.FAIL}Sam.py Message: Run was aborted by client with Status Code {status} - closing Sampyhub in 5 seconds...{bcolors.ENDC}")
    time.sleep(5) 
    sys.exit(status)

ImportError

ImportError isn't an explicit function, so there is no defined example or use case. However, you can find them at the imports section, with the first being at line 5.

Format

try:
    import module_name
except ImportError:
    print("give_module_description")
    print("module_name module is not installed. Run 'pip install module_name' to continue.")
    time.sleep(5)
    kill(412)

Actual Function

You can find it dotted around the script, but the first one is found on line 5.

try: # We use a try statement so it doesn't crash
    import click # Core - So we can get user input
except ImportError:
    print("CLICK (Command Line Interface Creation Kit) is a Python 3 module which allows developers to get user input in their code.")
    print("CLICK module is not installed. Run 'pip install click' to continue.")
    time.sleep(5)
    kill(412)
Clone this wiki locally