试卷.txt文件转json格式-多选题

2024-02-04 05:38
文章标签 json 格式 txt 试卷 多选题

本文主要是介绍试卷.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格式-多选题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/676491

相关文章

easyui同时验证账户格式和ajax是否存在

accountName: {validator: function (value, param) {if (!/^[a-zA-Z][a-zA-Z0-9_]{3,15}$/i.test(value)) {$.fn.validatebox.defaults.rules.accountName.message = '账户名称不合法(字母开头,允许4-16字节,允许字母数字下划线)';return fal

php中json_decode()和json_encode()

1.json_decode() json_decode (PHP 5 >= 5.2.0, PECL json >= 1.2.0) json_decode — 对 JSON 格式的字符串进行编码 说明 mixed json_decode ( string $json [, bool $assoc ] ) 接受一个 JSON 格式的字符串并且把它转换为 PHP 变量 参数 json

[数据集][目标检测]血细胞检测数据集VOC+YOLO格式2757张4类别

数据集格式:Pascal VOC格式+YOLO格式(不包含分割路径的txt文件,仅仅包含jpg图片以及对应的VOC格式xml文件和yolo格式txt文件) 图片数量(jpg文件个数):2757 标注数量(xml文件个数):2757 标注数量(txt文件个数):2757 标注类别数:4 标注类别名称:["Platelets","RBC","WBC","sickle cell"] 每个类别标注的框数:

Python脚本:TXT文档行数统计

count = 0 #计数变量file_dirs = input('请输入您要统计的文件根路径:')filename = open(file_dirs,'r') #以只读方式打开文件file_contents = filename.read() #读取文档内容到file_contentsfor file_content in file_contents:

一步一步将PlantUML类图导出为自定义格式的XMI文件

一步一步将PlantUML类图导出为自定义格式的XMI文件 说明: 首次发表日期:2024-09-08PlantUML官网: https://plantuml.com/zh/PlantUML命令行文档: https://plantuml.com/zh/command-line#6a26f548831e6a8cPlantUML XMI文档: https://plantuml.com/zh/xmi

struts2中的json返回指定的多个参数

要返回指定的多个参数,就必须在struts.xml中的配置如下: <action name="goodsType_*" class="goodsTypeAction" method="{1}"> <!-- 查询商品类别信息==分页 --> <result type="json" name="goodsType_findPgae"> <!--在这一行进行指定,其中lis是一个List集合,但

mysql中导入txt文件数据的操作指令

1 表tt的格式:    CREATE TABLE `tt` (   `ind` int NOT NULL auto_increment,   `name` char(100) default NULL,   PRIMARY KEY  (`ind`)  )   2 文件d.txt的内容示例:  1,a  2,b  3,c

特殊JSON解析

一般的与后台交互;都会涉及到接口数据的获取;而这里的数据一般情况就是JSON 了;JSON 解析起来方便;而且数据量也较小一些;所以JSON在接口数据返回中是个很不错的选择。 下面简单说下JSON解析过程中的一些案例: 这里我用到了三方的架包:fastjson-1.1.39.jar 架包 可以在我的博客中找到下载;或者网上找下 很多的; 这里主要就是映射  关系了;这就要求:实体类的名称和

单精度浮点数按存储格式转为整数的程序

///#include<cstdio>//-----------------union int_char{unsigned char ch[4];float i;};void out_put(union int_char x)//x86是小端对其模式,即最数据的最低位存储在地址的最低位上。{printf("单精度浮点数值为:%f\n",x.i,x.i);printf("存储位置从左到右

[数据集][目标检测]智慧农业草莓叶子病虫害检测数据集VOC+YOLO格式4040张9类别

数据集格式:Pascal VOC格式+YOLO格式(不包含分割路径的txt文件,仅仅包含jpg图片以及对应的VOC格式xml文件和yolo格式txt文件) 图片数量(jpg文件个数):4040 标注数量(xml文件个数):4040 标注数量(txt文件个数):4040 标注类别数:9 标注类别名称:["acalcerosis","fertilizer","flower","fruit","grey