我目前正在循环中运行一组文件,并检查它们的答案。目前,我希望存储使用%run file_name.py运行文件时初始化的get变量
我在下面附上了两个例子,一个是文件本身,它有3个答案。第二个是我用来比较它们的代码。
s = 'Amsterdam'
# Print out 'e' using indexing
answer1 = s[2]
print(answer1)
s ='Amsterdam'
# Reverse the string using slicing
answer2 = s[1]
print(answer2)
answer3 = s[::-1]
print(answer3)for i in range(1,num_questions+1):
%run {i}.py
answers = # HOW DO I MAKE LISTS BASED ON THE NUMBER OF VALUES RETURNED
if manual == 'N':
correct_answer_key,question = BitGrading.mannual_answer_key(1)
print(f'\n The correct answer key for {question} is {correct_answer_key}')
Grading.grade_question('Q1',student_ids,grade_sheet,answers,correct_answer_key[0])
print(f'\n{grade_sheet.loc[grade_sheet.ID == student_ids[0]]}')
else:
Grading.grade_question('Q1',student_ids,grade_sheet,answers,correct_answer[0])
grade_sheet.loc[grade_sheet.ID == student_ids[0]]我的主要关注点是根据返回的变量数量自动将答案存储在列表中。答案的格式将始终相同,即answer1、answer2、answer3等。
发布于 2020-09-04 03:44:42
如果你的文件只给出答案作为输出,你可以使用
import subprocess
output = subprocess.check_output(['python', '%pathToPYFile%']) # executes the file and saves the output
answers = output.decode('utf-8').split('\r\n')[:-1] # deletes an empty element at the end
print(answers)https://stackoverflow.com/questions/63730398
复制相似问题