The 24th to write the Python file base

Source: Internet
Author: User

Write---> Write string

Writelines---> Write string sequence (sequence: a bunch of strings, separated by commas. For example: dictionaries, lists, tuples)

File_obj.write (Content_obj)

Content_obj + ' \ n ' #me: If you do not add \ n, the content written is not wrapped.

EG1:

File_obj=open (' Test.txt ', ' W ') file exists then open, does not exist then create

File_obj=open (' test.txt ', ' w+ ') ' + ' stands for readable, writable

EG2:

File_obj=open (' Test.txt ', ' W ')

Conta= "Hello"

Contb= "World"

Contc= "Jeapedu.com"

File_obj.write (conta + ' \ n ') #me: If you do not add \ nthe content is not wrapped "= =" Conta= "hello\n"

File_obj.write (contb + ' \ n ')

File_obj.write (CONTC + ' \ n ')

File_obj.close ()

Help (File.writelines)----View assistance

Accept only one parameter, which can be a sequence sequence: list, dictionary, tuple

EG1:

File_obj=open (' Test.txt ', ' W ')

Conta= "hello\n"

contb= "world\n"

Contc= "Jeapedu.com\n"

File_obj.writelines ([CONTA,CONTB,CONTC]) List

File_obj.writelines ((CONTA,CONTB,CONTC)) tuple

File_obj.writelines ({CONTA,CONTB,CONTC}) dictionary

File_obj.close ()











The 24th to write the Python file base

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.