bat执行python代码结果保存到text文件中

问题举例:
test.py文件:print("hello")
test.bat文件:@echo off
cd Z:\python
start python test.py >> Z:\python\data.txt
test.py内容一句话:print("hello")
test.bat内容:@echo on
cd Z:\python
start python test.py >>Z:\python\data.txt
出不来结果,我查了资料,又写了一个bat文件:
test1.bat内容:@echo off
cd Z:\python
call "test.bat" >>Z:\python\data.txt
start notepad Z:\python\data.txt
这样就在data中出现test.bat文件的内容,并不是我想要的结果。
任务一: 编写 bat文件完成运行 py文件,把返回值存在 text文件中。
任务二:能把结果存在excel文件中吗,我想对结果进行分析,提供思路即可。

返回值存在 text文件, 这个用python写就好,存excel用python的pandas库就好:

import os
fname = os.path.join('Z:', 'python', 'data.txt')
with open(fname, 'w') as f:
    f.write('hello')

温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-01-21
没明白你想要表达什么问题追问

test.py内容一句话:print("hello")
test.bat内容:@echo on
cd Z:\python
start python test.py >>Z:\python\data.txt
出不来结果,我查了资料,又写了一个bat文件:

相似回答