代码之家  ›  专栏  ›  技术社区  ›  Panfeng Li

python中“./path”和“path”的区别

  •  0
  • Panfeng Li  · 技术社区  · 7 年前

    一般来说,它们对我来说都可以,我很少遇到它们不同的情况。

    今天,当我尝试加载自定义定义的模块时:

    >>> import tensorflow as tf
    >>> encoding = tf.load_op_library('./ops/encoding.so')
    >>> dir(encoding)
    ['LIB_HANDLE', 'OP_LIST', '_AggregateGradOutput', '_InitOpDefLibrary', '_ScaleL2GradOutput', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', '_aggregate_grad_outputs', '_collections', '_common_shapes', '_context', '_core', '_dtypes', '_errors', '_execute', '_op_def_lib', '_op_def_library', '_op_def_pb2', '_op_def_registry', '_ops', '_pywrap_tensorflow', '_scale_l2_grad_outputs', '_six', '_tensor_shape', 'aggregate', 'aggregate_eager_fallback', 'aggregate_grad', 'aggregate_grad_eager_fallback', 'scale_l2', 'scale_l2_eager_fallback', 'scale_l2_grad', 'scale_l2_grad_eager_fallback', 'tf_export']
    

    他们给出了不同的结果。

    >>> encoding = tf.load_op_library('ops/encoding.so')
    >>> dir(encoding)
    ['LIB_HANDLE', 'OP_LIST', '_InitOpDefLibrary', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', '_collections', '_common_shapes', '_context', '_core', '_dtypes', '_errors', '_execute', '_op_def_lib', '_op_def_library', '_op_def_pb2', '_op_def_registry', '_ops', '_pywrap_tensorflow', '_six', '_tensor_shape', 'tf_export']
    

    这个 tf.load_op_library :

    Args:
    
        library_filename: Path to the plugin. Relative or absolute filesystem path to a dynamic library file.
    
    Returns:
    
        A python module containing the Python wrappers for Ops defined in the plugin.
    

    因为很难用关键词搜索相关问题 ./ python 我想知道你能否给我一些建议。

    谢谢您!

    1 回复  |  直到 7 年前
        1
  •  1
  •   Chai T. Rex    7 年前

    tf.load_op_library calls the C function TF_LoadLibrary . 根据 the documentation for that function :

    加载由库文件名指定的库,并注册该库中存在的操作和内核。

    将“库文件名”传递到平台特定的机制,以动态加载库。确定库的确切位置的规则是平台特定的,此处不作记录。

    成功后,将OK置于状态并返回新创建的库句柄。调用方拥有库句柄。

    失败时,将错误状态置于状态并返回空值。

    我认为平台的“动态加载库的平台特定机制”可能不会检查当前目录,因此必须指定 ./ 在文件名前面显式使用当前目录。

    推荐文章