Python_ use CSV module to parse CSV file __python

Source: Internet
Author: User
Tags parse csv file

Import CSV is required before use.

Here is an example of reading a CSV file:

Csvreader = Csv.reader (open (' avdecode_list.csv ', ' RB ')    #以只读方式取得csv文件中内容 for

row in Csvreader:   #行循环
    Parameterstr = ', '. Join (Row)    #通过逗号连接每行每个单元格的内容    
    parameters = Parameterstr.split (', ')    #得到每个单元格的内容
    
    Name = parameters[1]        #将第一个单元格的内容赋值给name
    component = parameters[2]
    executiontype = parameters[3]
    format = parameters[4]
    inputfile = parameters[5]
    mode = parameters[6]
    ...

Here is an example of a CSV file:

CSVFile = open ("Avencode_list.csv", ' WB ')   #打开一个csv文件
csvwriter = Csv.writer (csvfile)     #创建一个writer
titlelist = [' No. ', ' Name ', ' component ', ' executiontype ', ' outputfile ']     #创建一个list
csvwriter.writerow (titlelist)   #将该list写入csv文件, each content in the list occupies one cell                  
csvfile.close ()


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.