Python 通过批处理文件运行时未执行py文件
我试图在按钮按下事件时按顺序运行批处理文件 我有solution.py&尝试通过批处理文件solution.bat作为 启动/等待Python.exe“C:/…../solution.py 此文件将在以后完全执行(&p) Test.py有以下代码&am尝试从批处理文件Test.bat作为 启动/等待Python.exe“C:/…../Test.pyPython 通过批处理文件运行时未执行py文件,python,Python,我试图在按钮按下事件时按顺序运行批处理文件 我有solution.py&尝试通过批处理文件solution.bat作为 启动/等待Python.exe“C:/…../solution.py 此文件将在以后完全执行(&p) Test.py有以下代码&am尝试从批处理文件Test.bat作为 启动/等待Python.exe“C:/…../Test.py import datetime import time Date = datetime.datetime.now().strftime("Date:
import datetime
import time
Date = datetime.datetime.now().strftime("Date: %d/%m/%y")
time = datetime.datetime.now().strftime("Time: %H:%M:%S")
text_file = open("C:XXX.txt", "w")
text1_file = open("C:YYY.txt", "w")
import os
for file in os.listdir("C:\ZZZ"):
if file.endswith(".txt"):
print(file)
cloud_file = open(file, "r")
if '#####' in open(file).read():
print ####
else:
Print $$$$$
text_file = open("C:XXX.txt", "r")
count = 0
for line in text_file.readlines():
for word in line.split():
if word == 'Pass':
count= count + 1
print('Pass',count,'TC')
text_file = open("C:XXX.txt", "r")
count1 = 0
for line in text_file.readlines():
for word in line.split():
if word == 'Fail':
count1= count1 + 1
print('Fail',count1,'TC')
text1_file = open("C:YYY.txt", "w")
count = 0
for line in text1_file.readlines():
for word in line.split():
if word == 'Pass':
count= count + 1
print('Pass',count,'TC')
text1_file = open("C:YYY.txt", "w")
count1 = 0
for line in text1_file.readlines():
for word in line.split():
if word == 'Fail':
count1= count1 + 1
Print('Fail',count1,'TC')
按顺序,solution.bat打开并完全执行solution.py文件。然后打开test.bat并执行代码test.py,直到只创建xxx.txt和YYY.txt文件,其余代码不执行
任何帮助。我喜欢这个答案。
listdir(“C:\ZZZ”)中的路径被重新定位到主文件夹并获得输出。
多亏了大家在您的代码中出现了一些语法错误,我并不奇怪它没有运行。我建议你先把它们修好。您使用的是哪个版本的python?您有裸的
打印
,还有打印
功能(更不用说无效的打印
)。然后是缩进错误……也许可以尝试关闭打开的文件,或者使用with open
语句,而不仅仅是open