代码语言:javascript复制
一、打开文件
文件句柄 =
open('文件路径', '模式')
打开文件时,需要指定文件路径和以何等方式打开文件,打开后,即可获取该文件句柄,日后通过此文件句柄对该文件操作。
打开文件的模式有:
- r,只读模式(默认)。
- w,只写模式。【不可读;不存在则创建;存在则删除内容;】
- a,追加模式。【可读; 不存在则创建;存在则只追加内容;】
" " 表示可以同时读写某个文件
- r ,可读写文件。【可读;可写;可追加】
- w ,写读
- a ,同a
"U"表示在读取时,可以将 r n rn自动转换成 n (与 r 或 r 模式同使用)
- rU
- r U
"b"表示处理二进制文件(如:FTP发送上传ISO镜像文件,linux可忽略,windows处理二进制文件时需标注)
- rb
- wb
- ab
def close(self, *args, **kwargs): # real signature unknown 关闭文件 pass
def fileno(self, *args, **kwargs): # real signature unknown 文件描述符
pass
def flush(self, *args, **kwargs): # real signature unknown 刷新文件内部缓冲区 pass
def isatty(self, *args, **kwargs): # real signature unknown 判断文件是否是同意tty设备 pass
def read(self, *args, **kwargs): # real signature unknown 读取指定字节数据 pass
def readable(self, *args, **kwargs): # real signature unknown 是否可读 pass
def readline(self, *args, **kwargs): # real signature unknown 仅读取一行数据 pass
def seek(self, *args, **kwargs): # real signature unknown 指定文件中指针位置 pass
def seekable(self, *args, **kwargs): # real signature unknown 指针是否可操作 pass
def tell(self, *args, **kwargs): # real signature unknown 获取指针位置 pass
def truncate(self, *args, **kwargs): # real signature unknown 截断数据,仅保留指定之前数据 pass
def writable(self, *args, **kwargs): # real signature unknown 是否可写 pass
def write(self, *args, **kwargs): # real signature unknown 写内容 pass
def __getstate__(self, *args, **kwargs): # real signature unknown
pass
def __init__(self, *args, **kwargs): # real signature unknown
pass
@staticmethod # known case of __new__
def __new__(*args, **kwargs): # real signature unknown
""" Create and return a new object. See help(type) for accurate signature. """
pass
def __next__(self, *args, **kwargs): # real signature unknown
""" Implement next(self). """
pass
def __repr__(self, *args, **kwargs): # real signature unknown
""" Return repr(self). """
pass