Python read/write CSV

Source: Internet
Author: User

For a simple record, read and write about both of these files:

Read/write CSV:

Import csv# read Data def getcsv (filename= "xxxxxxxx"):    rows=[]    with open (filename, ' RB ') as F:        readers= Csv.reader (f,delimiter= ', ', quotechar= ' | ')        Next (Readers,none) for        row in readers:            rows.append (Row)        print rows# write Data def  writecsv (filename= " Xxxxxxxxx "):    with open (filename, ' WB ') as F:        write =csv.writer (f)        Write.writerow (" Element "," system ")        data={            (' Selenium ', ' webdriver python '),            (' Appnium ', ' Android Python '),            (' Appnium ', ' iOS ')            }        Write.writerows (data)        f.close () if __name__== ' __main__ ':    writecsv ()    getcsv ()

For the use of with, you can refer to other people's explanations:

http://blog.csdn.net/suwei19870312/article/details/23258495/
About Readers=csv.reader (f,delimiter= ', ', quotechar= ' | ') The explanation of this sentence can be referred to the explanation of others:
http://blog.csdn.net/kaka_yidian/article/details/13000235
Read to a column:
1 defGetcsv (value1,value2,filename="xxxxxxxx"):2Rows=[]3with open (filename,'RB') as F:4Readers=csv.reader (f,delimiter=',', quotechar='|')5 Next (Readers,none)6          forRowinchReaders:7 rows.append (Row)8         returnrows (value1,value2)9 if __name__=='__main__':Ten     PrintGetcsv (0,0)

Python read/write CSV

Related Article

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.