关于python的help功能问题
发布网友
发布时间:2022-04-22 13:05
我来回答
共1个回答
热心网友
时间:2022-04-18 04:11
你好,首先你可以通过help(format)看到基本的信息,然后这个信息有提示,需要看更多的信息可以通过help('FORMATTING')。
如果你需要将相关的信息发送出来,可以用下面的代码:
import os
import sys
out = sys.stdout
sys.stdout = open("help.txt", "w")
help('FORMATTING')
sys.stdout.close()
sys.stdout = out
和填充,对齐的信息如下:
Most built-in types implement the following options for format
specifications, although some of the formatting options are only
supported by the numeric types.
A general convention is that an empty format string ("""") proces
the same result as if you had called "str()" on the value. A non-empty
format string typically modifies the result.
The general form of a *standard format specifier* is:
format_spec ::= [[fill]align][sign][#][0][width][grouping_option][.precision][type]
fill ::= <any character>
align ::= "<" | ">" | "=" | "^"
sign ::= "+" | "-" | " "
width ::= digit+
grouping_option ::= "_" | ","
precision ::= digit+
type ::= "b" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" | "n" | "o" | "s" | "x" | "X" | "%"
If a valid *align* value is specified, it can be preceded by a *fill*
character that can be any character and defaults to a space if
omitted. It is not possible to use a literal curly brace (p"{"q or
p"}"q) as the *fill* character in a formatted string literal or when
using the "str.format()" method. However, it is possible to insert a
curly brace with a nested replacement field. This limitation doesnot
affect the "format()" function.
The meaning of the various alignment options is as follows:
+-----------+------------------------------------------------------------+
| Option | Meaning |
+===========+============================================================+
| "'<'" | Forces the field to be left-aligned within the available |
| | space (this is the default for most objects). |
+-----------+------------------------------------------------------------+
| "'>'" | Forces the field to be right-aligned within the available |
| | space (this is the default for numbers). |
+-----------+------------------------------------------------------------+
| "'='" | Forces the padding to be placed after the sign (if any) |
| | but before the digits. This is used for printing fields |
| | in the form n+000000120o. This alignment option is only |
| | valid for numeric types. It becomes the default when n0o |
| | immediately precedes the field width. |
+-----------+------------------------------------------------------------+
| "'^'" | Forces the field to be centered within the available |
| | space. |
+-----------+------------------------------------------------------------+