I think that you have hit a limitation of the RUN_PYTHON_CODE() function: it only accepts single-line commands.
Two possible ways to go:
Usually you'd try to get your .py commands into a .py file. Then you just exec() the Python file (or use the cmd language "file python read file_name = ...." ). This can be a bit of a pain, though, if you're not sure where your .py file is. You might need to add to sys.path, or similar, to get the PATH setup to find your .py file.
Here's another Pythonic way, using a list comprehension:
Python code, test this out:
junk=[print(item) for item in range(4)]
I've not tried with your exact code, but I think it is this:
var set var=pydummy int=(eval(run_python_code("junk = [os.remove(f) for f in filelist]")))
Why should someone take the burden and write Python code in command language instead of putting it in a file and edit this with an editor with syntax highlighting or even a more complex environment like IDLE, Anaconda,Spyder, PYCharm, Eclipse or whatever ?
Another workaround with four additional lines would be to dump the desired content into an intermediate python file and simply read/cleanup after creation.
file text open file="test.py" open_mode = overwrite
file text write format="import glob, os, os.path"
file text write format="cwd = os.getcwd()"
file text write format="filelist = glob.glob(os.path.join(cwd, 'tmp_*'))"
var set var = DeleteIt int = (eval(REMOVE_FILE("test.py"))
It's still using a python file, but saves the administrative work of having files installed & found on the target machine (especially TOPDIR is one of the top-forbidden zones in our IT)