Python3 input and output, python3 Input and Output

Source: Internet
Author: User

Python3 input and output, python3 Input and Output

Pyhon3 io Input and Output
Myread = open ('e:/cmd.txt ') # open () will return a file object
Mywrite = open ('e:/3/example .txt ', 'w') # The following w will be overwritten if the file exists. If the file does not exist, it will be created.
For myrd in myread: # print cyclically
Print (myrd)
Mywrite. write (myrd)
Myread = open ('e:/cmd.txt ', 'R') # r. open the file in read-only mode. The file pointer is placed at the beginning of the file.

Myread = open ('e:/cmd.txt ', 'rb') # r, which is opened in binary format and used for read-only

Myread = open ('e:/cmd.txt ', 'rb +') # r, which is opened in binary format and used for read-only operations. It is equivalent to adding fields in the text.
Myread. write (B 'sfasfaf') # It must be added. Otherwise, an error is returned.
Myread. seek (5) # Move to the sixth byte of the file
Myread = open ('e:/path. PNG ', 'rb ')
Mywrite = open ('e:/path. PNG ', 'wb') # r, which is opened in binary mode. If the write object exists, it will be overwritten. If the write object does not exist, it will be created.
For I in myread:
Mywrite. write (I)

Myread = open ('e: // path/h.txt ', 'w') # Enter characters in txt
Zs = 'gfgd'
Myread. write (zs)

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.