Python Error Summary

Source: Internet
Author: User

    • CSV file write Chinese garbled problem and read-write error

In python2.7, the following error occurred after running the program.

1 Traceback (most recent):213File"c:/users/administrator/desktop/python_code/untitled0.py", line 57,inch<module>4File=open ('Da.csv','W', newline="')5TypeError:'NewLine'  isAn invalid keyword argument forThis function

Through the degree of Niang search only know, this is due to the python3.x version of the Open () function is not the same usage.

1 # Change the File=open (' Da.csv ', ' W ', newline= ') to the following to resolve 2 file=open ('da,csv','wb') # python2.x using "WB" You can avoid empty lines 3 file.write (codecs. BOM_UTF8) # Solve Chinese garbled problem

To solve this problem you need to start with the following line of code:

1 Import SYS 2 Import Codecs 3 Reload (SYS) 4 sys.setdefaultencoding ('utf-8')

Summarize:

Although it is a small mistake, but did not find out before still think for a long while, can not locate the cause of the mistake.

The ability to program is still to be improved, and more hands-on exercises are needed to gradually grow up in one mistake.

The best way to resolve anxiety is to act immediately.

Python Error Summary

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.