Inspired from https://blog.petrzemek.net/2014/03/23/restarting-a-python-script-within-itself/
def restart():
        import sys
        print("argv was",sys.argv)
        print("sys.executable was", sys.executable)
        print("restart now")
        import os
        os.execv(sys.executable, ['python'] + sys.argv)
Works like a charm (--a pycharm?)! I am running a discord bot that I quite frequently manage, and having a command like this is extremely helpful! I've looked everywhere and this is the only one that's worked so far! One thing that I'd change just for optimization's sake:
['python'] + sys.argv->['python', sys.argv]as the+operator is not optimized for this purpose in python...nevermind, it doesn't work if you do that... Do you know why that happens @plieningerweb?