❶ 关于python的help功能问题
你好,首先你可以通过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. |
+-----------+------------------------------------------------------------+
❷ python的dir和help用法
当你给dir()提供一个模块名字时,它返回在那个模块中定义的名字的列表。当没有为其提供参数时,
它返回当前模块中定义的名字的列表。
dir()
函数使用举例:
>>> import sys # 获得属性列表,在这里是sys模块的属性列表
>>> dir(sys)
['__displayhook__', '__doc__', '__excepthook__', '__name__',
'__package__', '__stderr__', '__stdin__', '__stdout__',
'_clear_type_cache', '_compact_freelists','_current_frames',
'_getframe', 'api_version', 'argv', ...]
如果您需要快速获取任何的Python函数或语句的信息,那么您可以使用内置的“help”(帮助)功能。这是非常有用的,尤其是当使用翻译提示符时,例如,运行‘help(print)”——这将显示print函数的帮助--用于打印东西到屏幕上。
help()函数使用举例:
>>> help(print)
Help on built-in function print in mole builtins:
print(...)
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
...