class FastGFile: 没有线程锁定的文件I/O包装器。class GFile: 没有线程锁定的文件I/O包装器。class Open: 没有线程锁定的文件I/O包装器。Copy(...): 将数据从oldpath复制到newpath。DeleteRecursively(...):递归删除dirname下的所有内容。Exists(...): 确定路径是否存在。Glob(...): 返回与给定模式匹配的文件列表。IsDirectory(...): 返回路径是否为目录。ListDirectory(...): 返回目录中包含的项的列表。MakeDirs(...): 创建一个目录和所有父/中间目录。MkDir(...): 创建名为“dirname”的目录。Remove(...): 删除位于“filename”的文件。Rename(...): 重命名或移动文件/目录。Stat(...): 返回给定路径的文件统计信息。Walk(...): 递归目录树生成器。tf.gfile.Copy(
oldpath,
newpath,
overwrite=False
)参数:
overwrite:布尔值,如果为false,则newpath将被现有文件占用。可能产生的异常:
errors.OpError: If the operation fails.tf.gfile.DeleteRecursively(dirname)参数:
可能产生的异常:
errors.OpError: If the operation fails.tf.gfile.Exists(filename)参数:
返回值:
可能产生的异常:
errors.OpError: Propagates any errors reported by the FileSystem API.1、__init____init__(
name,
mode='r'
)模式
返回文件打开时的模式。
名称
返回文件名称
3、__enter____enter__()使用with语句。
4、__exit____exit__(
unused_type,
unused_value,
unused_traceback
)使用with语句。
5、__iter____iter__()6、closeclose()FileIO关门。应被调用以刷新可写文件。
7、flushflush()刷新可写文件。这只能确保数据在没有任何关于是否写入磁盘的保证的情况下离开进程。这意味着数据可以在应用程序崩溃时存活,但不一定能在操作系统崩溃时存活。
8、nextnext()9、readread(n=-1)以字符串的形式返回文件的内容。从文件中的当前位置开始读取。
参数:
返回值:
10、readlinereadline()从文件中读取下一行。在末尾留下“\n”。
11、readlinesreadlines()返回列表中文件的所有行。
12、seekseek(
offset=None,
whence=0,
position=None
)查找文件中的偏移量。(弃用参数)
参数:
offset:相对于where参数的字节数。13、seekableseekable()返回True,因为FileIO支持seek()/tell()的随机访问操作
14、sizesize()返回文件的大小。
15、telltell()返回文件中的当前位置。
16、writewrite(file_content)将file_content写入文件。附加到文件末尾。
tf.gfile.Glob(filename)参数:
filename:字符串或字符串的可迭代。通配符匹配操作符(s)的模式。返回值:
可能产生的异常:
errors.OpError: If there are filesystem / directory listing errors.返回路径是否为目录。
tf.gfile.IsDirectory(dirname)参数:
返回值:
tf.gfile.ListDirectory(dirname)这个列表的顺序是任意的。它不包含特殊条目“.”和“..”。
参数:
返回值:
tf.gfile.MakeDirs(dirname)如果dirname已经存在且可写,则成功。
参数:
可能产生的异常:
errors.OpError: If the operation fails.tf.gfile.MkDir(dirname)参数:
可能产生的异常:
errors.OpError: If the operation fails.tf.gfile.Remove(filename)参数:
可能产生的异常:
errors.OpError: Propagates any errors reported by the FileSystem API. E.g., NotFoundError if the file does not exist.tf.gfile.Rename(
oldname,
newname,
overwrite=False
)参数:
overwrite:布尔值,如果为false,则newname被现有文件占用是一个错误可能产生的异常:
errors.OpError: If the operation fails.tf.gfile.Stat(filename)参数:
返回值:
可能产生的异常:
errors.OpError: If the operation fails.tf.gfile.Walk(
top,
in_order=True
)参数:
产生: