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


Python Util.read_file方法代码示例

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


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

示例1: parse

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import read_file [as 别名]
    def parse(path):
        """Parse an ``.ensime`` config file from S-expressions.

        Args:
            path (str): Path of an ``.ensime`` file to parse.

        Returns:
            dict: Configuration values with string keys.
        """

        def paired(iterable):
            """s -> (s0, s1), (s2, s3), (s4, s5), ..."""
            cursor = iter(iterable)
            return zip(cursor, cursor)

        def unwrap_if_sexp_symbol(datum):
            """Convert Symbol(':key') to ':key' (Symbol isn't hashable for dict keys).
            """
            return datum.value() if isinstance(datum, sexpdata.Symbol) else datum

        def sexp2dict(sexps):
            """Transforms a nested list structure from sexpdata to dict."""
            newdict = {}

            # Turn flat list into associative pairs
            for key, value in paired(sexps):
                key = str(unwrap_if_sexp_symbol(key)).lstrip(':')

                # Recursively transform nested lists
                if isinstance(value, list) and value and isinstance(value[0], list):
                    newdict[key] = [sexp2dict(val) for val in value]
                elif isinstance(value, list) and value and isinstance(value[0], sexpdata.Symbol):
                    newdict[key] = sexp2dict(value)
                else:
                    newdict[key] = value

            return newdict

        conf = sexpdata.loads(Util.read_file(path))
        return sexp2dict(conf)
开发者ID:ensime,项目名称:ensime-sublime,代码行数:42,代码来源:config.py

示例2: http_port

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import read_file [as 别名]
 def http_port(self):
     return int(Util.read_file(os.path.join(self.cache_dir, "http")))
开发者ID:ensime,项目名称:ensime-sublime,代码行数:4,代码来源:launcher.py

示例3: World

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import read_file [as 别名]
import timeit

map1 = "maps/map1.txt"
map2 = "maps/map2.txt"
map3 = "maps/map3.txt"

b_map1 = "generatedpaths/bfs/map1.txt"
b_map2 = "generatedpaths/bfs/map2.txt"
b_map3 = "generatedpaths/bfs/map3.txt"

d_map1 = "generatedpaths/dfs/map1.txt"
d_map2 = "generatedpaths/dfs/map2.txt"
d_map3 = "generatedpaths/dfs/map3.txt"

print "\nBFS - Map1"
world = World(Util.read_file(map1), b_map1)
bfs_search = BFS(world)
print timeit.Timer(bfs_search.search).timeit(1)

print "\nBFS - Map2"
world = World(Util.read_file(map2), b_map2)
bfs_search = BFS(world)
bfs_search.search()
print timeit.Timer(bfs_search.search).timeit(1)

print "\nBFS - Map3"
world = World(Util.read_file(map3), b_map3)
bfs_search = BFS(world)
bfs_search.search()
print timeit.Timer(bfs_search.search).timeit(1)
开发者ID:muneebshahid,项目名称:MAS,代码行数:32,代码来源:main.py


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