Python notes (1)

Source: Internet
Author: User

* ******** This document is intended for beginners to avoid detours, click ************************

1. Remember to set the encoding method at the beginning of the. py file. The format is as follows.

# Coding = UTF-8

** Remember Chinese Characters

 

2. Do not overwrite the append file.

Csvfile = file (filepath, 'a + B ') writer = csv. writer (csvfile) writer. writerow (["name", "Age", "gender"])

The append parameter is: +,

Note: writer. the parameter in the writerow () method is of the list type. To write 'hello' in column A1. writerow (['hello']), otherwise 'hello' will be regarded as a list and written into five columns.

When writing a csvfile, add 'B' to the created csvfile, that is, csv.writer(open('test.csv ', 'wb'). Otherwise, there will be a line break. The explanation found on the internet is: When python writes files normally, '\ n' is added to the end of each line by default, that is, 0x0D, while 0x0D0A is added to the end of the writerow command, therefore, for windows systems, there are two lines, while the 'B' parameter is used to write files in binary format. By default, 0x0D is not added.

3. global Variables

The global variables are defined. If you need to reference them in the method, the following is true:

Global variable name

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.