Location of Python read/write files and file pointers

Source: Internet
Author: User

Use read to read files and transmit the number of bytes to read

Write a file to pass the string to be written.

 

1. Write files

 

>>> F = open ('e: // test.txt ', 'w') <br/> A = [1, 2] <br/> F. write (a); <br/> traceback (most recent call last): <br/> file "<pyshell #13>", line 1, in <module> <br/> F. write (a); <br/> typeerror: Write () argument 1 must be STR, not list <br/> F. write ('Hello World'); <br/> 11 <br/> F. close () <br/>

2. Read files

>>> F = open ('e: // test.txt ', 'R') <br/> f. read (5) <br/> 'hello' <br/> f. seek (0, 1) <br/> 5 <br/> f. read () <br/> 'World' <br/> f. seek (0, 0) <br/> 0 <br/> f. read () <br/> 'Hello world' <br/> f. close () <br/>

 

Write can only write strings. To write other types of data, you must use the pickle package.

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.