Python3 common file writing method instance analysis

Source: Internet
Author: User
This article mainly introduces Python3 common methods for writing files, analyzes the conventional methods for writing files and improvement methods in details in the form of instances, as well as the techniques for writing files in segments, for more information about how to write data to a file in Python3, see the following example. Share it with you for your reference. The details are as follows:

'''''Created on Dec 18,201 2 write to a file @ author: liury_lab ''' # The simplest method is all_the_text = 'Hello Python' open ('d:/text.txt ', 'W '). write (all_the_text) all_the_data = B 'abcd1234' open ('d:/data.txt ', 'wb '). write (all_the_data) # better way file_object = open ('d:/text.txt ', 'w') file_object.write (all_the_text) file_object.close () # write list_of_text_strings = ['hello ', 'python', 'hello', 'World'] file_object = open ('d:/text.txt ', 'w') for string in list_of_text_strings: file_object.writelines (string) list_of_text_strings = ['hello', 'Python', 'hello', 'World'] file_object = open ('d:/text.txt ', 'w') file_object.writelines (list_of_text_strings)

I hope this article will help you with Python programming.

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.