"Python" IO programming

Source: Internet
Author: User

1. The concept of stream. Data exchange usually requires the establishment of two "water pipes".

2, synchronous IO and asynchronous IO. Asynchronous performance is high, but the programming model is complex.

3, Operation IO function is provided by the operating system! Both Java and Pyton are simply encapsulating low-level interfaces for developers to use.

"File Read and write"

Read the file

1, the simple

>>> f = open ('ask.txt'r')>>> F.read () ' I think you must be very busy recently.  '>>>

But remember to turn it off (the file object will account for the operating system resources)

>>> F.close ()

However, sometimes reading a file may throw an error, for example: The file does not exist. To ensure that the file is eventually turned off, you must use the Finally statement that will be executed.

Try :     = Open ('ask.txt'R')    print( F.read ())finally:    if  f:        f.close ()

There is an equivalent notation:

With open ('ask.txt') as F:    Print(F.read ())

2.

"Python" IO 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.