当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


Python tf.compat.path_to_str用法及代码示例

PathLike 对象的输入转换为 str 类型。

用法

tf.compat.path_to_str(
    path
)

参数

  • path 可以转换为路径表示的对象。

返回

  • str 对象。

PathLike 对象的任何 python 常量表示形式转换为字符串。如果输入不是PathLike 对象,则只需返回输入。

用法:

如果需要来自 os.PathLike 对象的简化 str 版本的路径

例子:

$ tf.compat.path_to_str('C:\XYZ\tensorflow\./.././tensorflow')
'C:\XYZ\tensorflow\./.././tensorflow' # Windows OS
$ tf.compat.path_to_str(Path('C:\XYZ\tensorflow\./.././tensorflow'))
'C:\XYZ\tensorflow\..\tensorflow' # Windows OS
$ tf.compat.path_to_str(Path('./corpus'))
'corpus' # Linux OS
$ tf.compat.path_to_str('./.././Corpus')
'./.././Corpus' # Linux OS
$ tf.compat.path_to_str(Path('./.././Corpus'))
'../Corpus' # Linux OS
$ tf.compat.path_to_str(Path('./..////../'))
'../..' # Linux OS

相关用法


注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.compat.path_to_str。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。