Python reads and writes CSV files in real combat

Source: Internet
Author: User

CSV Introduction

What is CSV? Everyone has heard of it, but I guess very few people can explain it in a comprehensive way, then the younger brother will caught dead a little bit. CSV I understand a file that stores data, which is stored in a comma as a partition (or, of course, with tabs).

Rules for CSV

1 The opening is not left empty to the behavior unit.

2 can contain or do not contain column name, including column name in the first line of the file.

31 rows of data do not span rows, no blank lines.

4 A comma (that is,) is used as a delimiter, the column is empty also to express its existence.

5 column Contents If there is a half-width quotation mark (that is, "), replace with a half-width double quotation mark (" ") escape, that is, use the half-width quotation mark (" ") to enclose the field value.

6 file read-write quotation marks, comma operation rules are mutually inverse.

7 Internal code format is not limited, can be ASCII, Unicode or other.

8 special characters are not supported

Python csv

The CSV module is built into Python and can be used directly by import CSV

The usual methods are as follows:

Writer, Dictwriter, reader, Dictreader

I should not explain, I do not know to check the meaning of English ... The dict is read and written by means of a dictionary.

Code Combat

How to obtain the source code please see the video


This article is from the "Cockroach Performance automation test brand" blog, please be sure to keep this source http://xqtesting.blog.51cto.com/4626073/1975472

Python reads and writes CSV files in real combat

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.