如何使用分隔符识别和打印字符串
How to identify and print string with the delimiters
我正在尝试制作一个 "Quiz Scanner ",它使用 OCR 在线扫描测验,这样我就可以自己从在线资源中编译测验,以便能够离线回答。我厌倦了复制和粘贴操作,而是使用 OCR。
我对 moment.The 部分的 OCR 部分没有任何问题,我现在遇到的问题是我需要将问题与选择分开,并将正确和错误的选择分开。下面是我尝试分离它们的过于简化的代码。
我需要将它们分开,因为我想将其导出到 excel 中的跨页 sheet。 Whosebug 社区一如既往地需要您的帮助
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])
sample quiz online
尝试在您的字符串中找到 @
个字符的索引,然后在两个索引分开后就是您的正确答案。
scannedmcq = 'Insert Question Here @ A(correct) > B > C > D'
result = scannedmcq[scannedmcq.index('@')+2]
print("Correct Answer is':", result)
我正在尝试制作一个 "Quiz Scanner ",它使用 OCR 在线扫描测验,这样我就可以自己从在线资源中编译测验,以便能够离线回答。我厌倦了复制和粘贴操作,而是使用 OCR。
我对 moment.The 部分的 OCR 部分没有任何问题,我现在遇到的问题是我需要将问题与选择分开,并将正确和错误的选择分开。下面是我尝试分离它们的过于简化的代码。
我需要将它们分开,因为我想将其导出到 excel 中的跨页 sheet。 Whosebug 社区一如既往地需要您的帮助
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])
sample quiz online
尝试在您的字符串中找到 @
个字符的索引,然后在两个索引分开后就是您的正确答案。
scannedmcq = 'Insert Question Here @ A(correct) > B > C > D'
result = scannedmcq[scannedmcq.index('@')+2]
print("Correct Answer is':", result)