Would like to insert python code or run ipython code in a windows bat file (Not in a separate .py file).
After searching, could not find any solution.
EDIT: This is for ipython code (not python).
Try this (batch-python polyglot script ):
0<0# : ^
'''
@echo off
echo batch code
python %~f0 %*
exit /b 0
'''
print("python code")
the '''
respectively starts and ends python multi line comments.
0<0# : ^
is more interesting - due to redirection priority in batch it will be interpreted like :0<0# ^
by the batch script which is a label which execution will be not displayed on the screen. The caret at the end will escape the new line and second line will be attached to the first line.For python it will be 0<0
statement and a start of inline comment.
The credit goes to siberia-man
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With