You could use a hybrid technic, this solution works also with an python import.
1>2# : ^
'''
@echo off
echo normal
echo batch code
echo Switch to python
python "%~f0"
exit /b
rem ^
'''
print "This is Python code"
The batch code is in a multiline string '''
so this is invisible for python.
The batch parser doesn't see the python code, as it exits before.
The first line is the key.
It is valid for batch as also for python!
In python it's only a senseless compare 1>2
without output, the rest of the line is a comment by the #
.
For batch 1>2#
is a redirection of stream 1
to the file 2#
.
The command is a colon :
this indicates a label and labeled lines are never printed.
Then the last caret simply append the next line to the label line, so batch doesn't see the '''
line.