'settrace', 'stderr', 'stdin', 'stdout', 'subversion', 'version', 'version_info',
'warnoptions', 'winver']
The dir function simply returns a list containing the string names of all the attributes
in any object with attributes; it’s a handy memory jogger for modules at the interactive
prompt. For example, we know there is something called sys.version, because the
name version came back in the dir result. If that’s not enough, we can always consult
the doc string of built-in modules:
>>> sys.__doc__
"This module provides access to some objects used or maintained by the\ninterpre
ter and to functions that interact strongly with the interpreter.\n\nDynamic obj
ects:\n\nargv -- command line arguments; argv[0] is the script pathname if known
\npath -- module search path; path[0] is the script directory, else ''\nmodules
-- dictionary of loaded modules\n\ndisplayhook -- called to show results in an i
...lots of text deleted here..."
Paging Documentation Strings
The doc built-in attribute just shown usually contains a string of documentation,
but it may look a bit weird when displayed this way—it’s one long string with embedded
end-line characters that print as \n, not as a nice list of lines. To format these strings
for a more humane display, you can simply use a print function-call statement:
>>> print(sys.__doc__)
This module provides access to some objects used or maintained by the
interpreter and to functions that interact strongly with the interpreter.
Dynamic objects:
argv -- command line arguments; argv[0] is the script pathname if known
path -- module search path; path[0] is the script directory, else ''
modules -- dictionary of loaded modules
...lots of lines deleted here...
The print built-in function, unlike interactive displays, interprets end-line characters
correctly. Unfortunately, print doesn’t, by itself, do anything about scrolling or paging
and so can still be unwieldy on some platforms. Tools such as the built-in help func-
tion can do better:
>>> help(sys)
Help on built-in module sys:
NAME
sys
FILE
(built-in)
MODULE DOCS
http://docs.python.org/library/sys
78 | Chapter 2: System Tools