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


Python flags.text_wrap方法代碼示例

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


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

示例1: test_text_wrap_raises_on_excessive_indent

# 需要導入模塊: from absl import flags [as 別名]
# 或者: from absl.flags import text_wrap [as 別名]
def test_text_wrap_raises_on_excessive_indent(self):
    """Ensure an indent longer than line length raises."""
    self.assertRaises(ValueError,
                      flags.text_wrap, 'dummy', length=10, indent=' ' * 10) 
開發者ID:abseil,項目名稱:abseil-py,代碼行數:6,代碼來源:flags_formatting_test.py

示例2: test_text_wrap_raises_on_excessive_first_line

# 需要導入模塊: from absl import flags [as 別名]
# 或者: from absl.flags import text_wrap [as 別名]
def test_text_wrap_raises_on_excessive_first_line(self):
    """Ensure a first line indent longer than line length raises."""
    self.assertRaises(
        ValueError,
        flags.text_wrap, 'dummy', length=80, firstline_indent=' ' * 80) 
開發者ID:abseil,項目名稱:abseil-py,代碼行數:7,代碼來源:flags_formatting_test.py

示例3: usage

# 需要導入模塊: from absl import flags [as 別名]
# 或者: from absl.flags import text_wrap [as 別名]
def usage(shorthelp=False, writeto_stdout=False, detailed_error=None,
          exitcode=None):
  """Writes __main__'s docstring to stderr with some help text.

  Args:
    shorthelp: bool, if True, prints only flags from the main module,
        rather than all flags.
    writeto_stdout: bool, if True, writes help message to stdout,
        rather than to stderr.
    detailed_error: str, additional detail about why usage info was presented.
    exitcode: optional integer, if set, exits with this status code after
        writing help.
  """
  if writeto_stdout:
    stdfile = sys.stdout
  else:
    stdfile = sys.stderr

  doc = sys.modules['__main__'].__doc__
  if not doc:
    doc = '\nUSAGE: %s [flags]\n' % sys.argv[0]
    doc = flags.text_wrap(doc, indent='       ', firstline_indent='')
  else:
    # Replace all '%s' with sys.argv[0], and all '%%' with '%'.
    num_specifiers = doc.count('%') - 2 * doc.count('%%')
    try:
      doc %= (sys.argv[0],) * num_specifiers
    except (OverflowError, TypeError, ValueError):
      # Just display the docstring as-is.
      pass
  if shorthelp:
    flag_str = FLAGS.main_module_help()
  else:
    flag_str = FLAGS.get_help()
  try:
    stdfile.write(doc)
    if flag_str:
      stdfile.write('\nflags:\n')
      stdfile.write(flag_str)
    stdfile.write('\n')
    if detailed_error is not None:
      stdfile.write('\n%s\n' % detailed_error)
  except IOError as e:
    # We avoid printing a huge backtrace if we get EPIPE, because
    # "foo.par --help | less" is a frequent use case.
    if e.errno != errno.EPIPE:
      raise
  if exitcode is not None:
    sys.exit(exitcode) 
開發者ID:abseil,項目名稱:abseil-py,代碼行數:51,代碼來源:app.py


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