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 0 | Value 1 | Value 2 | Value 3 | Value 4 | Value 5 | |
Row 0 | a01 | Mark | 22 | male | yes | 126 |
Row 1 | a02 | Jane | 31 | female | yes | 152 |
Row 2 | a03 | Philip | 28 | male | no | 88 |
Row 3 | a04 | John | 19 | male | yes | 115 |
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模块。