ioutils
import yaml
import json
import csv
import configparser class IoUtils(object): """
dependency: pip install pyyaml yaml_r: read yaml ,return dict yaml_w: write yaml,data type is dict json_r: read json file ,return dict json_w: write json file ,data type is dict csv_r: read csv file ,return list format is:
[
[header],
[column1,column2,....],
.....
] csv_w: write data into csv file
data format is :
[
[],[],
......
]
or like this format:
[
(),()
......
] read_config: read ini file :
return items of section or object of config or only option value """ def yaml_r(self, filepath) -> dict:
with open(filepath, 'r') as f:
data = yaml.load(f, Loader=yaml.Loader)
return data def yaml_w(self, filepath, data: dict):
with open(filepath, 'w', encoding="utf-8") as f:
yaml.dump(data, f) def json_r(self, filepath) -> dict:
with open(filepath, 'r+')as f:
return json.load(f) def json_w(self, filepath, data: dict):
with open(filepath, "w+", encoding="utf-8")as f:
json.dump(data, f, indent=2, ensure_ascii=False) def csv_r(self, csv_path) -> list: with open(file=csv_path, mode="r")as f:
data = csv.reader(f, dialect='excel', delimiter=',', quotechar='|')
data_set = [i for i in data]
return data_set def csv_w(self, csv_path, data):
with open(file=csv_path, mode='w', newline='')as f:
wt = csv.writer(f)
wt.writerows(data) def readConfig(self, filepath, section=None, option=None,
section_only=False, option_only=False,):
config = configparser.ConfigParser()
config.read(filepath)
if section and section_only:
return config.items(section)
if option and option_only:
return config.get(section=section,option=option)
if not section_only and not option_only:
return config def opens(self, filepath, mode, data=None):
"""r or w file """
if mode == "r" or mode == "r+":
with open(filepath, mode)as file:
lines = file.readlines()
return lines
if mode == "w" or mode == "r+" and not data:
with open(filepath, mode)as file:
file.write(data)
io
ioutils的更多相关文章
- apache.commons.io.IOUtils: 一个很方便的IO工具库(比如InputStream转String)
转换InputStream到String, 比如 //引入apache的io包 import org.apache.commons.io.IOUtils; ... ...String str = IO ...
- Java程序员的日常—— IOUtils总结
以前写文件的复制很麻烦,需要各种输入流,然后读取line,输出到输出流...其实apache.commons.io里面提供了输入流输出流的常用工具方法,非常方便.下面就结合源码,看看IOUTils都有 ...
- IO - IOUtils
Commons IO is a library of utilities to assist with developing IO functionality. There are four main ...
- Commons IO - IOUtils
IOUtils is a general IO stream manipulation utilities. This class provides static utility methods fo ...
- 文件输入输出流工具: IOUtils使用总结
序言 以前写文件的复制很麻烦,需要各种输入流,然后读取line,输出到输出流...其实apache.commons.io里面提供了输入流输出流的常用工具方法,非常方便.下面就结合源码,看看IOUTil ...
- Delphi 2010 新增功能之: IOUtils 单元(6): TPath(结构体) 的方法与属性
以后路径相关的处理, 用 IOUtils.TPath 就很方便了. //较常用的方法: TPath.GetTempPath; {获取临时文件夹路径} TPath.Ge ...
- Apache IOUtils的使用
IOUtils 与 FileUtilsCommons IO 是 apache 的一个开源的工具包,封装了 IO操作的相关类,使用 Commons IO 可以很方便的读写文件 commons.jar 包 ...
- IOUtils总结
参考:https://www.cnblogs.com/xing901022/p/5978989.html 常用的静态变量 在IOUtils中还是有很多常用的一些变量的,比如换行符等等 public s ...
- 【commons-io】File对文件与目录的处理&FileUtis,IOUtils,FilenameUtils工具的使用
-------------------File的使用-------------- 1.File类对文件的处理 1.1目录结构: 1.2测试对文件Test.txt处理: // 测试文件 @Test p ...
- Tomcat中使用commons-io-2.5发生的错误java.lang.ClassNotFoundException: org.apache.commons.io.IOUtils
关键词:IntelliJ IDEA.Tomcat.commons-io-2.5.jar.java.lang.ClassNotFoundException: org.apache.commons.io. ...
随机推荐
- ❀❀ selenium 学习网站 ★★★★★
http://edu.51cto.com/course/course_id-7320.html Selenium IDE WEB自动化测试入门视频课程(上)(共10课时)_在线自学视频教程_51C ...
- java课后作业2
动手动脑 编写一个方法,使用以上算法生成指定数目(比如1000个)的随机整数 import java.util.Random;import java.util.Scanner;public class ...
- C语言-指针深度分析
1.变量回顾 程序中的变量只是—段存储空间的别名,那么是不 是必须通过这个别名才能使用这段存储空间? 2.思考 下面的程序输出什么?为什么? ; int* p = &i; p ...
- The number of set(位运算+状态dp)一道十分美妙的题目哦!!!!!!
Given you n sets.All positive integers in sets are not less than 1 and not greater than m.If use the ...
- JMeter压力测试,http请求压测,5分钟让你学会如何压测接口!
JMeter压力测试 官网:https://jmeter.apache.org 最新款的jmeter需要java8的支持,所以请自行安装jdk8.这里就不啰嗦了. 可以根据自己的系统下载zip或者是t ...
- 微信小程序图片设置圆角进入页面闪动
transform变形 当我们通过某些行为触发页面进行大面积绘制的时候,浏览器由于没有事先准备,应付渲染够呛,于是掉帧,于是卡顿.而will-change则是真正的行为触发之前告诉浏览器:“我待会儿就 ...
- 第三十九篇 入门机器学习——Numpy.array的基础操作——合并与分割向量和矩阵
No.1. 初始化状态 No.2. 合并多个向量为一个向量 No.3. 合并多个矩阵为一个矩阵 No.4. 借助vstack和hstack实现矩阵与向量的快速合并.或多个矩阵快速合并 No.5. 分割 ...
- nginx知识学习
设备: macbook 有用的命令行: sudo nginx -t 测试nginx是否正常 sudo nginx -s reload 平滑重启 配置目录: /usr/local/etc/nginx ...
- 514 ,css不同选择器的权重(css层叠的规则)
!important规则最重要,大于其它规则 行内样式规则,加1000 eg,<html> <head> </head> <body> & ...
- 【C语言】一堆数组中存放了10个小于100的整数,请编程对所有数据按照从小到大的顺序进行排序,若个位数相等,则按照十位从小到大的顺序排序,输出排序后的结果
分析:取余,判断个位是否相等,利用冒泡法排序 #include <stdio.h> int main() { ] = { ,,,,,,,,, };/*数组*/ int i, j, k; ; ...