当前位置: 首页>>代码示例>>Python>>正文


Python path.pop方法代码示例

本文整理汇总了Python中os.path.pop方法的典型用法代码示例。如果您正苦于以下问题:Python path.pop方法的具体用法?Python path.pop怎么用?Python path.pop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在os.path的用法示例。


在下文中一共展示了path.pop方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: unflatten

# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import pop [as 别名]
def unflatten(flat_config):
  """Transforms a flat configuration dictionary into a nested dictionary.

  Example:
    {
      "a": 1,
      "b.c": 2,
      "b.d.e": 3,
      "b.d.f": 4,
    }
  would be transformed to:
    {
      "a": 1,
      "b": {
        "c": 2,
        "d": {
          "e": 3,
          "f": 4,
        }
      }
    }

  Args:
    flat_config: A dictionary with strings as keys where nested configuration
      parameters are represented with period-separated names.

  Returns:
    A dictionary nested according to the keys of the input dictionary.
  """
  config = {}
  for path, value in flat_config.items():
    path = path.split(".")
    final_key = path.pop()
    nested_config = config
    for key in path:
      nested_config = nested_config.setdefault(key, {})
    nested_config[final_key] = value
  return config 
开发者ID:google-research,项目名称:exoplanet-ml,代码行数:40,代码来源:config_util.py

示例2: unflatten

# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import pop [as 别名]
def unflatten(flat_config):
  """Transforms a flat configuration dictionary into a nested dictionary.

  Example:
    {
      "a": 1,
      "b.c": 2,
      "b.d.e": 3,
      "b.d.f": 4,
    }
  would be transformed to:
    {
      "a": 1,
      "b": {
        "c": 2,
        "d": {
          "e": 3,
          "f": 4,
        }
      }
    }

  Args:
    flat_config: A dictionary with strings as keys where nested configuration
        parameters are represented with period-separated names.

  Returns:
    A dictionary nested according to the keys of the input dictionary.
  """
  config = {}
  for path, value in flat_config.items():
    path = path.split(".")
    final_key = path.pop()
    nested_config = config
    for key in path:
      nested_config = nested_config.setdefault(key, {})
    nested_config[final_key] = value
  return config 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:40,代码来源:config_util.py


注:本文中的os.path.pop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。