Read and write excel in Python and save it in MySQL

Source: Internet
Author: User

For a sudden idea: simple to solve with Python is good. Now it's time to fill out the basic function pits needed for this project. The rest is the pit of AI and data presentation.

The pits we met today are:

1, from Excel read the Chinese is garbled

2, Chinese writing MySQL database is garbled

Resolution 1:

The method is actually very simple, just a word:

str = str.encode (' Utf-8 ')

After that, str can display Chinese correctly in both console and variables.

Resolution 2:

The method is also very simple, there is only one sentence:

To connect to the database, you need to specify the database encoding as UTF8, as follows: MySQLdb.connect (port= ' localhost ', user= ' root ', password= ' xxxx ', db= ' xxxxxx ', charset= ' UTF8 ')

Note that the UTF8 here can not be written utf-8, otherwise it will error.

Read and write excel in Python and save it in MySQL

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.