【发布时间】:2020-06-27 11:53:21
【问题描述】:
我正在尝试制作 python 程序来为用 c++ 编写的作业评分。 我的笔记本电脑操作系统是窗口,所以我安装了 g++ 以使用子进程命令。 这是我的代码。
Python 代码:
import subprocess
import os
import glob
from openpyxl import Workbook
path='C:\\auto_scoring\\'
def write_csv(tc_num,ans):
score_book=Workbook()
def score(testcases):#scroing function
correct=True
for i,testcase in enumerate(testcases):
if correct:
print(i+1,":correct")
else :
print(i+1,":wrong")
def exe_maker(filename):
ret=filename.rstrip('.cpp')+'.exe'
return ret
def execute(file):
ret=subprocess.check_output('check')
def get_testcase():
global path
text_name='test.txt'
r=open(text_name,mode='r',encoding='utf8')
text=r.read()
print(text)
def run():
file_list = glob.glob('*.cpp*')#cpp
for file in file_list:
exe_file=exe_maker(file)
command='g++ -o '+path+exe_file+" "+path+file
print(command)
subprocess.call(command)
print("start!")
ret=subprocess.check_output(file.rstrip('.cpp')+" 1").decode('ascii')
print(ret)
def main():
run()
def exp():
ret=subprocess.check_output('check').decode('ascii')
if ret=='1':
print('correct')
else:
print('wrong')
if __name__=='__main__':
main()
但我必须使用传递参数,例如 C++ 示例:
int main(int argc,char*argv){
cout<<argv[1];
}
我不想用这种东西。没有 int argc 和 char argv 的程序。 我只是想检查答案是否正确。 例如)输入:我的名字是k -> 输出:Hello K。 如果我不能制作程序,我必须每 100 个 c++ 文件运行一次...... 我真的需要帮助。 谢谢。
【问题讨论】: