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


Python Path.is_file方法代码示例

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


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

示例1: link

# 需要导入模块: from clldutils.path import Path [as 别名]
# 或者: from clldutils.path.Path import is_file [as 别名]
def link(args):
    """\
Complete linking of concepts to concept sets. If either CONCEPTICON_GLOSS or
CONCEPTICON_ID is given, the other is added.

concepticon link <concept-list>
"""
    conceptlist = Path(args.args[0])
    if not conceptlist.exists() or not conceptlist.is_file():
        conceptlist = data_path('conceptlists', args.args[0])
        if not conceptlist.exists() or not conceptlist.is_file():
            raise ParserError('no file %s found' % args.args[0])

    rewrite(conceptlist, Linker(conceptlist.stem))
开发者ID:SimonGreenhill,项目名称:concepticon-data,代码行数:16,代码来源:commands.py

示例2: stats

# 需要导入模块: from clldutils.path import Path [as 别名]
# 或者: from clldutils.path.Path import is_file [as 别名]
def stats(args):
    """
    cldf stats <DATASET>

    Print basic stats for CLDF dataset <DATASET>, where <DATASET> may be the path to
    - a CLDF metadata file
    - a CLDF core data file
    - a CLDF zip archive
    """
    if len(args.args) < 1:
        raise ParserError('not enough arguments')
    fname = Path(args.args[0])
    if not fname.exists() or not fname.is_file():
        raise ParserError('%s is not an existing directory' % fname)
    if fname.suffix == '.zip':
        ds = Dataset.from_zip(fname)
    elif fname.name.endswith(MD_SUFFIX):
        ds = Dataset.from_metadata(fname)
    else:
        ds = Dataset.from_file(fname)
    print(fname)
    stats_ = ds.stats
    print("""
Name: %s
Different languages: %s
Different parameters: %s
Rows: %s
""" % (
        ds.name,
        len(stats_['languages']),
        len(stats_['parameters']),
        stats_['rowcount']
    ))
开发者ID:LinguList,项目名称:pycldf,代码行数:35,代码来源:cli.py

示例3: _get_dataset

# 需要导入模块: from clldutils.path import Path [as 别名]
# 或者: from clldutils.path.Path import is_file [as 别名]
def _get_dataset(args):
    if len(args.args) < 1:
        raise ParserError('not enough arguments')
    fname = Path(args.args[0])
    if not fname.exists() or not fname.is_file():
        raise ParserError('%s is not an existing directory' % fname)
    if fname.suffix == '.json':
        return Dataset.from_metadata(fname)
    return Dataset.from_data(fname)
开发者ID:glottobank,项目名称:pycldf,代码行数:11,代码来源:__main__.py

示例4: load_normalized

# 需要导入模块: from clldutils.path import Path [as 别名]
# 或者: from clldutils.path.Path import is_file [as 别名]
def load_normalized(_path):
    """Normalization for quasi-identical strings which are often confused."""
    path = Path(_path)
    if not path.is_file():
        path = local_path(_path)
    norms = {}
    with path.open(encoding='utf-8') as handle:
        for line in handle:
            if not line.startswith('#') and line.strip():
                source, target = line.strip().split('\t')
                norms[eval('"' + source + '"')] = eval('r"' + target + '"')
    return norms
开发者ID:LinguList,项目名称:clpa,代码行数:14,代码来源:util.py

示例5: load_alias

# 需要导入模块: from clldutils.path import Path [as 别名]
# 或者: from clldutils.path.Path import is_file [as 别名]
def load_alias(_path):
    """
    Alias are one-character sequences which we can convert on a step-by step
    basis by applying them successively to all subsegments of a segment.
    """
    path = Path(_path)
    if not path.is_file():
        path = local_path(_path)

    alias = {}
    with path.open(encoding='utf-8') as handle:
        for line in handle:
            if not line.startswith('#') and line.strip():
                source, target = line.strip().split('\t')
                alias[eval('"' + source + '"')] = eval('r"' + target + '"')
    return alias
开发者ID:LinguList,项目名称:clpa,代码行数:18,代码来源:util.py

示例6: rewrite

# 需要导入模块: from clldutils.path import Path [as 别名]
# 或者: from clldutils.path.Path import is_file [as 别名]
def rewrite(fname, visitor, **kw):
    """Utility function to rewrite rows in tsv files.

    :param fname: Path of the dsv file to operate on.
    :param visitor: A callable that takes a line-number and a row as input and returns a \
    (modified) row or None to filter out the row.
    :param kw: Keyword parameters are passed through to csv.reader/csv.writer.
    """
    if not isinstance(fname, Path):
        assert isinstance(fname, string_types)
        fname = Path(fname)

    assert fname.is_file()
    tmp = fname.parent.joinpath('.tmp.' + fname.name)

    with UnicodeReader(fname, **kw) as reader_:
        with UnicodeWriter(tmp, **kw) as writer:
            for i, row in enumerate(reader_):
                row = visitor(i, row)
                if row is not None:
                    writer.writerow(row)
    shutil.move(tmp.as_posix(), fname.as_posix())
开发者ID:pombredanne,项目名称:clldutils,代码行数:24,代码来源:dsv.py

示例7: _existing_file

# 需要导入模块: from clldutils.path import Path [as 别名]
# 或者: from clldutils.path.Path import is_file [as 别名]
 def _existing_file(fname):
     fname = Path(fname)
     assert fname.exists() and fname.is_file()
     return fname
开发者ID:LinguList,项目名称:pycldf,代码行数:6,代码来源:dataset.py


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