0 basic python-2.17 files, open (), file ()

Source: Internet
Author: User

Today we're going to talk about files, and the built-in functions associated with files open and file

First we build a txt text file named "123" in the root directory of Python

We'll enter some text inside the file.

We put both the new file and the source code under the Python root directory.

Let's take a look at the code:

Handler=open ("123.txt") #由于把文件跟源代码建立在python的根目录,                        #所以这里的路径只需打名字即可for eachline in handler:    print (Eachline, End= ") Handler.close ()


Output Result:

File () is similar to open (), and the name is more consistent with the reading habit

Then we need to note that the above file is relatively small, if you put a 100m or more files into memory, the problem will occur, at that time we need additional processing methods, we need to read while writing, to reduce the use of memory, this we are expanding behind.

This is the section here, thank you.

------------------------------------------------------------------

Click to jump 0 basic python-Catalogue

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

0 basic python-2.17 files, open (), file ()

Related Article

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.