Update section about dir() in the tutorial.

This commit is contained in:
Ezio Melotti 2012-11-17 12:46:40 +02:00
parent 9236a4e99d
commit 820f2bdaf9

View file

@ -282,16 +282,21 @@ defines. It returns a sorted list of strings::
>>> import fibo, sys >>> import fibo, sys
>>> dir(fibo) >>> dir(fibo)
['__name__', 'fib', 'fib2'] ['__name__', 'fib', 'fib2']
>>> dir(sys) >>> dir(sys) # doctest: +NORMALIZE_WHITESPACE
['__displayhook__', '__doc__', '__excepthook__', '__name__', '__stderr__', ['__displayhook__', '__doc__', '__excepthook__', '__name__', '__package__',
'__stdin__', '__stdout__', '_getframe', 'api_version', 'argv', '__stderr__', '__stdin__', '__stdout__', '_clear_type_cache',
'builtin_module_names', 'byteorder', 'callstats', 'copyright', '_current_frames', '_getframe', '_mercurial', 'api_version', 'argv',
'displayhook', 'exc_clear', 'exc_info', 'exc_type', 'excepthook', 'builtin_module_names', 'byteorder', 'call_tracing', 'callstats',
'exec_prefix', 'executable', 'exit', 'getdefaultencoding', 'getdlopenflags', 'copyright', 'displayhook', 'dont_write_bytecode', 'exc_clear', 'exc_info',
'getrecursionlimit', 'getrefcount', 'hexversion', 'maxint', 'maxunicode', 'exc_traceback', 'exc_type', 'exc_value', 'excepthook', 'exec_prefix',
'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache', 'executable', 'exit', 'flags', 'float_info', 'float_repr_style',
'platform', 'prefix', 'ps1', 'ps2', 'setcheckinterval', 'setdlopenflags', 'getcheckinterval', 'getdefaultencoding', 'getdlopenflags',
'setprofile', 'setrecursionlimit', 'settrace', 'stderr', 'stdin', 'stdout', 'getfilesystemencoding', 'getobjects', 'getprofile', 'getrecursionlimit',
'getrefcount', 'getsizeof', 'gettotalrefcount', 'gettrace', 'hexversion',
'long_info', 'maxint', 'maxsize', 'maxunicode', 'meta_path', 'modules',
'path', 'path_hooks', 'path_importer_cache', 'platform', 'prefix', 'ps1',
'py3kwarning', 'setcheckinterval', 'setdlopenflags', 'setprofile',
'setrecursionlimit', 'settrace', 'stderr', 'stdin', 'stdout', 'subversion',
'version', 'version_info', 'warnoptions'] 'version', 'version_info', 'warnoptions']
Without arguments, :func:`dir` lists the names you have defined currently:: Without arguments, :func:`dir` lists the names you have defined currently::
@ -300,7 +305,7 @@ Without arguments, :func:`dir` lists the names you have defined currently::
>>> import fibo >>> import fibo
>>> fib = fibo.fib >>> fib = fibo.fib
>>> dir() >>> dir()
['__builtins__', '__doc__', '__file__', '__name__', 'a', 'fib', 'fibo', 'sys'] ['__builtins__', '__name__', '__package__', 'a', 'fib', 'fibo', 'sys']
Note that it lists all types of names: variables, modules, functions, etc. Note that it lists all types of names: variables, modules, functions, etc.
@ -311,10 +316,11 @@ want a list of those, they are defined in the standard module
:mod:`__builtin__`:: :mod:`__builtin__`::
>>> import __builtin__ >>> import __builtin__
>>> dir(__builtin__) >>> dir(__builtin__) # doctest: +NORMALIZE_WHITESPACE
['ArithmeticError', 'AssertionError', 'AttributeError', 'DeprecationWarning', ['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException',
'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'BufferError', 'BytesWarning', 'DeprecationWarning', 'EOFError',
'FloatingPointError', 'FutureWarning', 'IOError', 'ImportError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FloatingPointError',
'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning',
'IndentationError', 'IndexError', 'KeyError', 'KeyboardInterrupt', 'IndentationError', 'IndexError', 'KeyError', 'KeyboardInterrupt',
'LookupError', 'MemoryError', 'NameError', 'None', 'NotImplemented', 'LookupError', 'MemoryError', 'NameError', 'None', 'NotImplemented',
'NotImplementedError', 'OSError', 'OverflowError', 'NotImplementedError', 'OSError', 'OverflowError',
@ -323,18 +329,19 @@ want a list of those, they are defined in the standard module
'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'True', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'True',
'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError',
'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError',
'UserWarning', 'ValueError', 'Warning', 'WindowsError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning',
'ZeroDivisionError', '_', '__debug__', '__doc__', '__import__', 'ZeroDivisionError', '_', '__debug__', '__doc__', '__import__',
'__name__', 'abs', 'apply', 'basestring', 'bool', 'buffer', '__name__', '__package__', 'abs', 'all', 'any', 'apply', 'basestring',
'callable', 'chr', 'classmethod', 'cmp', 'coerce', 'compile', 'bin', 'bool', 'buffer', 'bytearray', 'bytes', 'callable', 'chr',
'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'classmethod', 'cmp', 'coerce', 'compile', 'complex', 'copyright',
'enumerate', 'eval', 'execfile', 'exit', 'file', 'filter', 'float', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval',
'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'execfile', 'exit', 'file', 'filter', 'float', 'format', 'frozenset',
'id', 'input', 'int', 'intern', 'isinstance', 'issubclass', 'iter', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input',
'len', 'license', 'list', 'locals', 'long', 'map', 'max', 'memoryview', 'int', 'intern', 'isinstance', 'issubclass', 'iter', 'len', 'license',
'min', 'object', 'oct', 'open', 'ord', 'pow', 'property', 'quit', 'range', 'list', 'locals', 'long', 'map', 'max', 'memoryview', 'min', 'next',
'raw_input', 'reduce', 'reload', 'repr', 'reversed', 'round', 'set', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit',
'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'range', 'raw_input', 'reduce', 'reload', 'repr', 'reversed', 'round',
'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super',
'tuple', 'type', 'unichr', 'unicode', 'vars', 'xrange', 'zip'] 'tuple', 'type', 'unichr', 'unicode', 'vars', 'xrange', 'zip']