當前位置: 首頁>>代碼示例>>Python>>正文


Python Path.open方法代碼示例

本文整理匯總了Python中clldutils.path.Path.open方法的典型用法代碼示例。如果您正苦於以下問題:Python Path.open方法的具體用法?Python Path.open怎麽用?Python Path.open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在clldutils.path.Path的用法示例。


在下文中一共展示了Path.open方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: write_data_file

# 需要導入模塊: from clldutils.path import Path [as 別名]
# 或者: from clldutils.path.Path import open [as 別名]
def write_data_file(comment_text, overwrite):
    lines = comment_text.split("\n")
    filename = Path(lines[0].split(":",1)[1].strip())
    if filename.exists() and not overwrite:
        return "Embedded data file %s already exists!  Run beastling with the --overwrite option if you wish to overwrite it.\n" % filename
    if not filename.parent.exists():
        filename.parent.mkdir()
    with filename.open("w", encoding='utf8') as fp:
        fp.write("\n".join(lines[1:]))
    return "Wrote embedded data file %s.\n" % filename
開發者ID:Anaphory,項目名稱:BEASTling,代碼行數:12,代碼來源:extractor.py

示例2: load_normalized

# 需要導入模塊: from clldutils.path import Path [as 別名]
# 或者: from clldutils.path.Path import open [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

示例3: from_file

# 需要導入模塊: from clldutils.path import Path [as 別名]
# 或者: from clldutils.path.Path import open [as 別名]
    def from_file(cls, bibFile, encoding='utf8', lowercase=False):
        """Create bibtex database from a bib-file.

        @param bibFile: path of the bibtex-database-file to be read.
        """
        if not isinstance(bibFile, Path):
            bibFile = Path(bibFile)
        if bibFile.exists():
            with bibFile.open(encoding=encoding) as fp:
                content = fp.read()
        else:
            content = ''

        return cls((Record.from_string('@' + m, lowercase=lowercase)
                    for m in re.split('^\s*@', content, 0, re.MULTILINE)))
開發者ID:cevmartinez,項目名稱:clld,代碼行數:17,代碼來源:bibtex.py

示例4: load_alias

# 需要導入模塊: from clldutils.path import Path [as 別名]
# 或者: from clldutils.path.Path import open [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

示例5: create

# 需要導入模塊: from clldutils.path import Path [as 別名]
# 或者: from clldutils.path.Path import open [as 別名]
    def create(self, req, filename=None, verbose=True):
        p = self.abspath(req)
        if not p.parent.exists():  # pragma: no cover
            p.parent.mkdir()
        tmp = Path('%s.tmp' % p.as_posix())

        if self.rdf:
            # we do not create archives with a readme for rdf downloads, because each
            # RDF entity points to the dataset and the void description of the dataset
            # covers all relevant metadata.
            #
            # TODO: write test for the file name things!?
            #
            with closing(GzipFile(
                    filename=Path(tmp.stem).stem, fileobj=tmp.open('wb')
            )) as fp:
                self.before(req, fp)
                for i, item in enumerate(page_query(self.query(req), verbose=verbose)):
                    self.dump(req, fp, item, i)
                self.after(req, fp)
        else:
            with ZipFile(tmp.as_posix(), 'w', ZIP_DEFLATED) as zipfile:
                if not filename:
                    fp = self.get_stream()
                    self.before(req, fp)
                    for i, item in enumerate(
                            page_query(self.query(req), verbose=verbose)):
                        self.dump(req, fp, item, i)
                    self.after(req, fp)
                    zipfile.writestr(self.name, self.read_stream(fp))
                else:  # pragma: no cover
                    zipfile.write(filename, self.name)
                zipfile.writestr(
                    'README.txt',
                    README.format(
                        req.dataset.name,
                        '=' * (
                            len(req.dataset.name)
                            + len(' data download')),
                        req.dataset.license,
                        TxtCitation(None).render(req.dataset, req)).encode('utf8'))
        if p.exists():  # pragma: no cover
            remove(p)
        move(tmp, p)
開發者ID:cevmartinez,項目名稱:clld,代碼行數:46,代碼來源:download.py

示例6: write

# 需要導入模塊: from clldutils.path import Path [as 別名]
# 或者: from clldutils.path.Path import open [as 別名]
 def write(self, fname, **kw):
     if not isinstance(fname, Path):
         fname = Path(fname)
     with fname.open('w', encoding='utf8') as fp:
         fp.write(self.write_string(**kw))
開發者ID:clld,項目名稱:clldutils,代碼行數:7,代碼來源:inifile.py


注:本文中的clldutils.path.Path.open方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。