We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.
Python But Bad
Jump to navigation
Jump to search
- This article is not detailed enough and needs to be expanded. Please help us by adding some more information.
Its like python,but if the interpreter detects any error,it deletes the entire code.
PLEASE MAKE A INTERPRETER FOR THIS IMPLEMENTED!!!!!!!!!!
Interpreter in Python (also a self interpreter)
import os,sys
with open(sys.argv[1],"r",encoding="utf-8") as f:
c=f.read()
try:
exec(c)
except:
os.remove(sys.argv[1])
Note that it is also possible to write an interpreter in C/C++ using Python C APIs.
Interpreter in Windows Batch File
@echo off
setlocal enabledelayedexpansion
set SCRIPT_FILE=%1
set IS_TEMP=0
REM ------------------------------------------------------------
REM If no file argument is provided, read from STDIN into a temp file
REM ------------------------------------------------------------
if "%SCRIPT_FILE%"=="" (
set IS_TEMP=1
set SCRIPT_FILE=%TEMP%\pycode_%RANDOM%.py
REM Read all lines from STDIN (piped or typed) and write to the temp file
findstr /r ".*" > "%SCRIPT_FILE%"
)
REM ------------------------------------------------------------
REM Check if the file exists (if it was an argument)
REM ------------------------------------------------------------
if not "%1"=="" (
if not exist "%SCRIPT_FILE%" (
echo Error: File "%SCRIPT_FILE%" not found.
exit /b 1
)
)
REM ------------------------------------------------------------
REM Execute the Python script
REM ------------------------------------------------------------
python "%SCRIPT_FILE%"
REM Capture the exit code (0 = success, non-zero = exception)
set EXIT_CODE=%ERRORLEVEL%
REM ------------------------------------------------------------
REM If an exception occurred (non-zero), delete the source code.
REM ------------------------------------------------------------
if %EXIT_CODE% NEQ 0 (
echo Exception detected. Deleting source code...
del /f "%SCRIPT_FILE%" 2>nul
)
REM ------------------------------------------------------------
REM If it was a temp file from STDIN, delete it cleanly
REM (even if it succeeded, to avoid clutter).
REM ------------------------------------------------------------
if %IS_TEMP%==1 (
if exist "%SCRIPT_FILE%" (
del /f "%SCRIPT_FILE%" 2>nul
)
)
exit /b %EXIT_CODE%
There are also a Linux/UNIX Bash version, which you can see it in Chinese (PSTF) since PrySigneToFry fed the program description to DeepSeek.