filename = os.path.splitext(os.path.basename(sys.argv[0]))[0]
if not os.path.exists(filename):
    sys.stderr.write(
        """'%s' is not recognized as an internal or external command,
operable program or batch file."""
         % filename)
sys.exit(9009)
How to run a python script without specifying the file extension (cross platform solution)?