-file method of Python application

Source: Internet
Author: User
Tags readline

#!/usr/bin/env python# *_* coding=utf-8 *_* "" "Desc: File Method ############################ #file. Read () #read ([size])-&G T     Read at most size bytes, returned as a string.               File.readline () ReadLine ([size]), next line from the file, as a string.        File.readlines () readlines ([size]), List of strings, each a line from the file.        Call ReadLine () repeatedly and return a list of the lines so read. The optional size argument, if given, is a approximate bound on the all number of bytes in the lines returned.fi                Le.xreadlines () Xreadlines (), returns self.  File.write () write (str), None.  Write string str to File.file.writelines () Writelines (sequence_of_strings), None.            Write the strings to the file.  Note that newlines is not added. The sequence can is any iterable object producing strings.     This is equivalent to calling write () for each string.file.truncate () Truncate ([size]), None.      Truncate the file to in the most size bytes.      Size defaults to the current file position, as returned by Tell (). File.seek () Seek (offset [, whence]) method changes the position of the current file. The offset variable represents the number of bytes to move.                 The from variable specifies the reference position at which to begin moving bytes. If from is set to 0, this means that the beginning of the file is used as the reference location for moving bytes. If set to 1, the current position is used as the reference location.           If it is set to 2, then the end of the file will be used as the reference location.                                 File.flush () File.tell () current file position, an integer (could be a long integer). File.next () File.close () ########### #不常用的方法 ############ #file. closed File.mode file.  Name File.isatty () # True or False.           True if the file is connected to a TTY device.                  File.readinto () #不用用这个 file.encoding # infrequently used File.errors # not commonly used File.newline # File.softspace File.fileno () Fileno ()          , integer "File descriptor".      This is needed for Lower-level file interfaces, such Os.read (). ############################## #version: 1.0 "" "Fo= Open (" E:/temp.txt ", ' R ') print" file name: ", Fo.nameprint" is closed: ", Fo.closedprint "access mode:", Fo.modeprint "at the end of whether to force a space:", fo.softspace

  

-file method of Python application

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.