一、打开文件
文件句柄 = open('文件路径''模式')

打开文件时,需要指定文件路径和以何等方式打开文件,打开后,即可获取该文件句柄,日后通过此文件句柄对该文件操作。

打开文件的模式有:

  • r,只读模式(默认)。
  • w,只写模式。【不可读;不存在则创建;存在则删除内容;】
  • a,追加模式。【可读;   不存在则创建;存在则只追加内容;】

"+" 表示可以同时读写某个文件

  • r+,可读写文件。【可读;可写;可追加】
  • w+,写读
  • a+,同a

"U"表示在读取时,可以将 \r \n \r\n自动转换成 \n (与 r 或 r+ 模式同使用)

  • rU
  • r+U

"b"表示处理二进制文件(如:FTP发送上传ISO镜像文件,linux可忽略,windows处理二进制文件时需标注)

  • rb
  • wb
  • ab
  •  1  def close(self, *args, **kwargs): # real signature unknown
     2         关闭文件
     3         pass
     4 
     5     def fileno(self, *args, **kwargs): # real signature unknown
     6         文件描述符  
     7         pass
     8 
     9     def flush(self, *args, **kwargs): # real signature unknown
    10         刷新文件内部缓冲区
    11         pass
    12 
    13     def isatty(self, *args, **kwargs): # real signature unknown
    14         判断文件是否是同意tty设备
    15         pass
    16 
    17     def read(self, *args, **kwargs): # real signature unknown
    18         读取指定字节数据
    19         pass
    20 
    21     def readable(self, *args, **kwargs): # real signature unknown
    22         是否可读
    23         pass
    24 
    25     def readline(self, *args, **kwargs): # real signature unknown
    26         仅读取一行数据
    27         pass
    28 
    29     def seek(self, *args, **kwargs): # real signature unknown
    30         指定文件中指针位置
    31         pass
    32 
    33     def seekable(self, *args, **kwargs): # real signature unknown
    34         指针是否可操作
    35         pass
    36 
    37     def tell(self, *args, **kwargs): # real signature unknown
    38         获取指针位置
    39         pass
    40 
    41     def truncate(self, *args, **kwargs): # real signature unknown
    42         截断数据,仅保留指定之前数据
    43         pass
    44 
    45     def writable(self, *args, **kwargs): # real signature unknown
    46         是否可写
    47         pass
    48 
    49     def write(self, *args, **kwargs): # real signature unknown
    50         写内容
    51         pass
    52 
    53     def __getstate__(self, *args, **kwargs): # real signature unknown
    54         pass
    55 
    56     def __init__(self, *args, **kwargs): # real signature unknown
    57         pass
    58 
    59     @staticmethod # known case of __new__
    60     def __new__(*args, **kwargs): # real signature unknown
    61         """ Create and return a new object.  See help(type) for accurate signature. """
    62         pass
    63 
    64     def __next__(self, *args, **kwargs): # real signature unknown
    65         """ Implement next(self). """
    66         pass
    67 
    68     def __repr__(self, *args, **kwargs): # real signature unknown
    69         """ Return repr(self). """
    70         pass
posted on 2016-04-20 19:39  geek3  阅读(227)  评论(0编辑  收藏  举报