本文整理匯總了Python中typing.TextIO.writelines方法的典型用法代碼示例。如果您正苦於以下問題:Python TextIO.writelines方法的具體用法?Python TextIO.writelines怎麽用?Python TextIO.writelines使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類typing.TextIO
的用法示例。
在下文中一共展示了TextIO.writelines方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _generate_template_to_writer
# 需要導入模塊: from typing import TextIO [as 別名]
# 或者: from typing.TextIO import writelines [as 別名]
def _generate_template_to_writer(self, base: pathlib.Path,
source: pathlib.Path,
writer: TextIO, **extra_variables):
try:
template = self.env.get_template(str(source))
except jinja2.TemplateNotFound as e:
raise GeneratorError("Template {} not found (search path {})"
.format(source,
self._format_search_path())
) from e
now = datetime.datetime.now(datetime.timezone.utc).astimezone()
comment = ("Generated on {} from {} by {}"
.format(now.strftime(self.DATETIME_FORMAT), source,
self._current_user))
relative_source = source.relative_to(base)
stream = template.stream(**self.config, **extra_variables,
comment=comment,
source_base=base,
source=relative_source,
source_dir=relative_source.parent)
writer.writelines(stream)