Python3.2 official documentation-standard interfaces and dir () Functions

Source: Internet
Author: User

4.2 Standard Interface

Python comes with library files for some standard modules. These library files are described in a separate document (python library file Introduction. Some modules are created in the interpreter. They provide non-verbal core operations that are not included in the interpreter for efficiency, or provide access to the underlying operating system, for example, system call. These modules ge perform different selection Configurations Based on the underlying platform. For example, the winreg module can only be provided on the window system, and the other special module is worth noting. sys, it is built in every python interpreter, with the variable sys. ps1 and sys. ps2 defines the main prompt and the strings used by this prompt.

>>> Import sys

>>> Sys. ps1

'>>>'

>>> Sys. ps2

'...'

>>> Sys. ps1 = 'C>'

C> print ('yuck! ')

Yuck!

C>

The two variables can be defined only when the interpreter is in interactive mode.

The sys. path variable is a list of strings that the system decides to search for the module path in the interpreter. It is initialized from the default environment variable pythonPATH or from the built-in default path when PYTHONPATH is empty. You can use the standard list operation to modify the configuration.

>>> Import sys

>>> Sys. path. append ('/ufs/guido/lib/python ')

4.3 dir () function

The built-in function dir is used to find the name of the module definition. It returns a list of sorted strings.

>>> Import fibo, sys

>>> Dir (fiber)

['_ Name _', 'fib ', '2 2']

>>> Dir (sys)

['_ Displayhook _', '_ doc _', '_ thook _', '_ name __', '_ stderr __',

'_ Stdin _', '_ stdout _', '_ getframe', 'api _ version', 'argv ',

'Builtin _ module_names ', 'byteorder', 'callstats', 'copyright ',

'Displayhook', 'exc _ info', 'mongothook ',

'Exec _ prefix', 'executable', 'exit ', 'getdefaultencoding', 'getdlopenflags ',

'Getrecursionlimit ', 'getrefercount', 'hversion', 'maxint', 'maxunicode ',

'Meta _ path', 'modules', 'path', 'path _ hooks', 'path _ importer_cache ',

'Platform', 'prefix', 'ps1', 'ps2 ', 'setcheckinterval', 'setdlopenflags ',

'Setprofile ', 'setcursionlimit', 'settrack', 'stderr', 'stdin ', 'stdout ',

'Version', 'version _ info', 'warnopexception']

If you do not have the dir () parameter, the module name you have defined will be traversed.

>>> A = [1, 2, 3, 4, 5]

>>> Import fibo

>>> Fib = maid

>>> Dir ()

['_ Builtins _', '_ doc _', '_ file _', '_ name _', 'A ', 'fib ', 'pipeline', 'sys']

Note that it will traverse all types of names: Variable modules and functions, etc.

Dir () cannot traverse the names of built-in functions and variables. If you want such a list, they are defined in the standard module buitins.

>>> Import builtins

>>> Dir (builtins)

['Arithmeticerror', 'assertionerror', 'bubuteerror', 'baseexception', 'buffer

Error ', 'byteswarning', 'destcationwarning', 'eoferror', 'ellipsis ', 'environme

NtError ', 'exception', 'false', 'floatingpointerror', 'ureurewarning', 'generato

RExit ', 'ioerror', 'initerror', 'initwarning', 'initationerror', 'indexerr

Or ', 'keyerror', 'keyboardinterrupt', 'lookuperror', 'memoryerror', 'nameerror ',

'None', 'notimplemented', 'notimplementederror ', 'osserror', 'overflowerror', 'pendingdeprecationwarning', 'referenceerror', 'runtimeerror', 'runtimewarning ','

StopIteration ', 'syntaxerror', 'syntaxwarning', 'systemerror', 'systemdelete', 'taberror', 'true', 'typeerror', 'unboundlocalerror', 'unicodedecodeerror ', 'unicodeencodeerror', 'unicodeerror', 'unicodetranslateerror', 'unicodewarning', 'userwarning', 'valueerror', 'warning', 'zerodivisionerror', '_ build_class __', '_ debug _', '_ doc _', '_ import _', '_ name _', '_ package __', 'abs ', 'all', 'any', 'ascii', 'bin', 'bool ', 'bytearray', 'bytes', 'chr', 'classmethod ', 'compute', 'compute', 'copyright', 'credits ', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval ', 'exec ', 'exit', 'filter', 'float', 'format', 'frozenset', 'getattr ', 'globals', 'hasattr', 'hash ', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass ', 'iter', 'len', 'license ', 'LIST', 'locals', 'map', 'max ', 'memoryview', 'Min', 'Next', 'object', 'oct', 'open ', 'ord ', 'pow', 'print', 'properties', 'quit', 'range', 'repr', 'reversed ', 'round', 'set ', 'setattr', 'slice ', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars ', 'zip']

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.