本文主要是介绍试卷.txt文件转json格式-多选题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
import re
f=open(r'E:\我的文件\多选题.txt')
fnew=open(r'E:\我的文件\多选题-json.txt','a')
sum=0
str0=''
f1=f.readlines()
print(f1)
print(f1[16])
for f0 in f1:sum=sum+1
print(sum)
i=0
while(i<sum):if (i%6==0):th=str(int(i*(1/6)+1))+'、'print(th)if f1[i].find('( AB )')!=-1:str0='{"name":"'+f1[i].replace('( AB )',' ')+'","daan": ["A","B"],'elif f1[i].find('( ABC )')!=-1:str0='{"name":"'+f1[i].replace('( ABC )',' ')+'","daan": ["A","B","C"],'elif f1[i].find('( ABCD )')!=-1:str0='{"name":"'+f1[i].replace('( ABCD )',' ')+'","daan": ["A","C","B","D",'elif f1[i].find('( ABCDE )')!=-1:str0='{"name":"'+f1[i].replace('( ABCDE )',' ')+'","daan": ["A","B","C","D","E"],'elif f1[i].find('( BC )')!=-1:str0='{"name":"'+f1[i].replace('( BC )',' ')+'","daan": ["B","C"],'elif f1[i].find('( BCD )')!=-1:str0='{"name":"'+f1[i].replace('( BCD )',' ')+'","daan": ["B","C","D"],'elif f1[i].find('( BCDE )')!=-1:str0='{"name":"'+f1[i].replace('( BCDE )',' ')+'","daan": ["B","C","D","E"],'elif f1[i].find('( CD )')!=-1:str0='{"name":"'+f1[i].replace('( CD )',' ')+'","daan": ["C","D"],'elif f1[i].find('( CDE )')!=-1:str0='{"name":"'+f1[i].replace('( CDE )',' ')+'","daan": ["C","D","E"],'elif f1[i].find('( DE )')!=-1:str0='{"name":"'+f1[i].replace('( DE )',' ')+'","daan": ["D","E"],'elif f1[i].find('( ACD )')!=-1:str0='{"name":"'+f1[i].replace('( ACD )',' ')+'","daan": ["A","C","D"],'elif f1[i].find('( ACDE )')!=-1:str0='{"name":"'+f1[i].replace('( ACDE )',' ')+'","daan": ["A","C","D","E"],'elif f1[i].find('( ADE )')!=-1:str0='{"name":"'+f1[i].replace('( ADE )',' ')+'","daan": ["A","D","E"],'elif f1[i].find('( AC )')!=-1:str0='{"name":"'+f1[i].replace('( AC )',' ')+'","daan": ["A","C"],'elif f1[i].find('( AD )')!=-1:str0='{"name":"'+f1[i].replace('( AD )',' ')+'","daan": ["A","D"],'elif f1[i].find('( AE )')!=-1:str0='{"name":"'+f1[i].replace('( AE )',' ')+'","daan": ["A","E"],'elif f1[i].find('( BD )')!=-1:str0='{"name":"'+f1[i].replace('( BD )',' ')+'","daan": ["B","D"],'elif f1[i].find('( BE )')!=-1:str0='{"name":"'+f1[i].replace('( BE )',' ')+'","daan": ["B","E"],'elif f1[i].find('( CE )')!=-1:str0='{"name":"'+f1[i].replace('( CE )',' ')+'","daan": ["","E"],'elif f1[i].find('( ACE )')!=-1:str0='{"name":"'+f1[i].replace('( ACE )',' ')+'","daan": ["A","C","E"],'elif f1[i].find('( BCE )')!=-1:str0='{"name":"'+f1[i].replace('( BC )',' ')+'","daan": ["B","C","E"],'elif f1[i].find('( BDE )')!=-1:str0='{"name":"'+f1[i].replace('( BDE )',' ')+'","daan": ["B","D","E"],'elif f1[i].find('( ABCE )')!=-1:str0='{"name":"'+f1[i].replace('( ABCE )',' ')+'","daan": ["A","B","C","E"],'elif f1[i].find('( ABDE )')!=-1:str0='{"name":"'+f1[i].replace('( ABDE )',' ')+'","daan": ["A","B","D","E"],'elif f1[i].find('( ACE )')!=-1:str0='{"name":"'+f1[i].replace('( ACE )',' ')+'","daan": ["A","C","E"],'elif f1[i].find('( ABE )')!=-1:str0='{"name":"'+f1[i].replace('( ABE )',' ')+'","daan": ["A","B","E"],'str0=str0.replace('\n','').replace(th,'')+'\n'i=i+1else:str0='"content":'+f1[i].replace('\n','')+ f1[i + 1].replace('\n','')+f1[i+2].replace('\n','')+f1[i+3].replace('\n','')+f1[i+4]+'"]},'str0=str0.replace('A','["').replace('B','","').replace('C','","').replace('D','","').replace('E','","').replace('\n','')+'\n'i=i+5print(str0)fnew.write(str0)
fnew.close()
f.close()
转前的.txt文件格式:
转后的json格式文件:
这篇关于试卷.txt文件转json格式-多选题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!