如何在bat文件中插入python代码? [英] How to insert python code in a bat file?

查看:267
本文介绍了如何在bat文件中插入python代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想插入python代码 或在Windows bat文件中运行ipython代码 (不在单独的.py文件中).

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.

这是针对ipython代码(而非python)的.

This is for ipython code (not python).

推荐答案

尝试以下操作(批量python多语言脚本):

Try this (batch-python polyglot script ):

0<0# : ^
''' 
@echo off
echo batch code
python %~f0 %*
exit /b 0
'''

print("python code")

'''分别开始和结束python多行注释.

the ''' respectively starts and ends python multi line comments.

0<0# : ^更为有趣-由于批量重定向的优先级,批处理脚本将像:0<0# ^那样解释该批处理脚本,该脚本是一个标签,其执行将不会显示在屏幕上.末尾的插入符号将转义新行,第二行将附加到第一行.对于python,它将是0<0语句和内联注释的开头.

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.

功劳归于西伯利亚人

这篇关于如何在bat文件中插入python代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆