Python file operations

Source: Internet
Author: User

1. Open File

Open (file, mode= ' R ', Buffering=-1, Encoding=none, Errors=none, Newline=none, Closefd=true, Opener=none)

  

2. Close the file

  Close (): Be sure to close the file after the file operation, Python can not be closed, because Python has an automatic garbage collection mechanism.

3. File read

Read (SIZE=-1): reads a size character from a file, reads the remaining characters when not given a size or a given negative value, and then returns as a string. Read () continues reading by default from the last read

  ReadLine (): reads a row

4. File Write

Write (str): Writes the string str to the file

Writelines (seq): Want a file to be written to a string sequence seq,seq should be an iterative object that returns a string

5. Move the file pointer

Seek (Offset,from): Move a file pointer in a file, starting from (0 for the starting position of the file, 1 for the current position, and 2 for the end of the file) to start offsetting offset bytes

Tell (): Returns the current location of the file

  

Python file operations

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.