CSV文件的一组行操作。

CSVrope的Python项目详细描述


此模块提供了一组简单的实用程序,用于检索、操作和 更新按行组织并包含在csv文件中的数据。

此模块的源代码位于:

https://github.com/thumbo/CSVrope

请通过问题跟踪器报告任何错误或功能请求。

安装依赖项

算法应该与Python3.5或更高版本一起使用,并且需要打开一些 源python模块。下面是工具集所需的依赖项 测试算法的版本:

  • Python3.5
  • 鼻1.3.7

安装

这个模块是用python包索引注册的。

安装包的最简单方法是使用pip。 首先确保您的pip版本是最新的:

https://pip.pypa.io/en/stable/installing/#upgrading-pip

…然后运行命令:

^{tt1}$

有关如何使用PIP的更多信息,请参阅指南:

https://packaging.python.org/installing/#use-pip-for-installing

另外,您也可以从以下网址下载软件包:

http://pypi.python.org/pypi/csvrope

…并以通常的方式编译它:

^{tt2}$

用法

csvrope模块包含一组用于检索的基本函数, 更新和操作csv文件中包含的数据。

当csv文件中包含的数据时,csvrope模块会给出最好的结果 以“表格”形式组织,如下例所示:

a01, Mark, 22,male, yes, 126

a02, Jane, 31,female, yes, 152

a03, Philip, 28,male, no, 88

a04, John, 19,male, yes, 115

Value 0Value 1Value 2Value 3Value 4Value 5
Row 0a01Mark22maleyes126
Row 1a02Jane31femaleyes152
Row 2a03Philip28maleno88
Row 3a04John19maleyes115
Row 4

为了使用以下函数,导入模块就足够了 在你的剧本里。

功能:

append_row(filename, row)
Append a row at the end of CSV file.
clear(filename)
Clear the CSV file.
count_rows(filename)
Return the number of rows present in the CSV file, 0 if none.
get_row(filename, row_index)
Return the row at row_index, from zero-index.
get_row_value(filename, row_index, value_index)
Return the value at value_index from the row at row_index, from zero-index.
get_row_values(filename, row_index, values_indexes)
Return the values at value_indexes from the row at row_index, from zero-index.
get_rows(filename)
Return a list containing all the rows of the CSV file.
get_rows_value(filename, value_index)
Return all the values at value_index from each row, from zero-index.
get_rows_with_value(filename, value_index, value_target)
Return a list containing all the rows that have value_target at value_index, from zero-index.
get_rows_with_values(filename, targets)

Return a list of lists, each containing the rows that match the targets, from zero-index.

Targets: [ [value1_index, value1_target], [value2_index, value2_target], … ]

Output: [ [rows with value1 ], [rows with value2], … ]

overwrite_row(filename, row_index, new_row)
Overwrite the row at row_index with the new_row, from zero-index.
print_rows(filename)
Print all the rows contained in the CSV file.
write_row(filename, row)
Clear the CSV file and write a single row.

关于本模块提供的功能, 请参见源代码存储库中的tests.py模块。

注释

csvrope模块打算与 标准的pythoncsv模块。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java优雅地完成SoftReference引用   java在cucumber框架的报告中生成json后,在何处调用jar文件(ATM)?   使用itext从html生成pdf时不采用java CSS样式   java错误:intellij错误。应用程序编程接口。cli。主要的   fitnesse Web测试Java测试客户端   java Powermock和Mockito。避免在模拟和存根同一类时对类进行静态初始化   Windows 10出现安装Java错误   java针对两种不同的注入依赖项运行单元测试   java firebase数据库的总值   排序Java7比较方法违反了它的一般约定(TimSort.java)   javascript Selenium:如何检查匿名函数的代码   java如何在安卓中解决“输入必须在256字节以下”的问题?   java如何解决实际上Mockito中没有与此模拟错误交互的问题   java线程在第一次运行时启动,然后在下一次运行时停止   java无法找到资源,尽管文件位于类路径中   java如何将LocalDate转换为特定的日期时间格式   用于Weblogic 10和Oracle 11g的java JDBC版本   java方法在结束之前返回