Home > Backend Development > Python Tutorial > Introduction to the use of python-csv

Introduction to the use of python-csv

高洛峰
Release: 2017-03-15 13:35:13
Original
2280 people have browsed it

Open csv

Introduction to the use of python-csv

Introduction to the use of python-csv

##

# -*- coding: utf8 -*-import csv  
with open('test.csv','rb') as my:  
    lines=csv.reader(my)  
    for line in lines:  
        print line
Copy after login


# -*- coding: utf8 -*-import csv
with open('text01.csv','wb') as my:      
    mywriter=csv.writer(my)  
    mywriter.writerow([1,'a'])  
    mywriter.writerow([2,'b'])  
    lists=[[3,5],[4,6]]  
    mywriter.writerows(lists)
Copy after login

Introduction to the use of python-csv


# -*- coding: utf8 -*-import csv
with open('text01.csv','rb') as my:  
    lines=csv.reader(my,csv.register_dialect('mydialect',delimiter='|', quoting=csv.QUOTE_ALL))  
    print lines.line_num  
    for line in lines:  
        print line
Copy after login

Introduction to the use of python-csv##Listen


# -*- coding: utf8 -*-import csv
with open('text.csv', 'wb') as csvfile:
    spamwriter = csv.writer(csvfile, delimiter=' ',
                            quotechar='|', quoting=csv.QUOTE_MINIMAL)
    spamwriter.writerow(['tiger'] * 5 + ['pig '])
    spamwriter.writerow(['cat', 'mouse', 'dog'])
Copy after login

Introduction to the use of python-csv

The above is the detailed content of Introduction to the use of python-csv. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template