我正在尝试制作一个“测验扫描器”,它使用OCR在线扫描测验,这样我就可以自己从在线来源汇编测验,以便能够离线回答它们。我厌倦了复制和粘贴的事情,只使用OCR代替。
我对光学字符识别部分没有问题,因为我现在遇到的问题是,我需要将问题从选择中分离出来,从正确和错误的选择中分离出来。下面是我尝试分离它们的一个过于简化的代码。
我需要将它们分开,因为我想将其导出到excel中的电子表格中。真的需要你的帮助,一如既往的堆栈溢出社区
import re
scannedmcq = 'Insert Question Here @ A(correct) > B > C > D' #Output of my OCR script
# What if this is the new string
# 'Insert Question Here > A > B > C @ D'
# The Delimiter @ Is the correct answer while > is the wrong answer
# How to Identify and print which part of the string has the delimiter @
text = re.split(r'[@>]\s*', line)
# Manually Printing the strings
print(text[0])
print(text[1])
print(text[2])
print(text[3])
print(text[4])发布于 2020-03-29 22:34:31
尝试在字符串中找到@字符的索引,然后在两个索引分开之后就是正确的答案。
scannedmcq = 'Insert Question Here @ A(correct) > B > C > D'
result = scannedmcq[scannedmcq.index('@')+2]
print("Correct Answer is':", result)https://stackoverflow.com/questions/60915274
复制相似问题