How to run python code in Windows batch (bat) files

Here’s the bit of tricky batch file magic that does it:

@setlocal enabledelayedexpansion && python -x "%~f0" %* & exit /b !ERRORLEVEL!
#start python code here
print "hello world"

The way it works is that the first line of the file does two different things.

1. starts python interpreter passing the name of the file in, and the -x option will tell it to skip the first line (containing .bat file code)
2. When python finishes the script exits.

This nifty trick makes it much nicer for writing admin scripts with python on Windows.


Code Formating for Flex

This is one thing flex and flash are missing. Code formating.
I've tested few eclipse plugins but none of them worked like this one. You can download it from

Just copy it in your ecplise/plugins folder and restart. You can also import/export your settings in a .properties file


Ctrl-Shift-F is the default shortcut key to format the selected code. Also it's possible to assign another shortcut combination or using the red circled button on the image above.