當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。