17db96d56Sopenharmony_ci:mod:`rlcompleter` --- Completion function for GNU readline 27db96d56Sopenharmony_ci=========================================================== 37db96d56Sopenharmony_ci 47db96d56Sopenharmony_ci.. module:: rlcompleter 57db96d56Sopenharmony_ci :synopsis: Python identifier completion, suitable for the GNU readline library. 67db96d56Sopenharmony_ci 77db96d56Sopenharmony_ci.. sectionauthor:: Moshe Zadka <moshez@zadka.site.co.il> 87db96d56Sopenharmony_ci 97db96d56Sopenharmony_ci**Source code:** :source:`Lib/rlcompleter.py` 107db96d56Sopenharmony_ci 117db96d56Sopenharmony_ci-------------- 127db96d56Sopenharmony_ci 137db96d56Sopenharmony_ciThe :mod:`rlcompleter` module defines a completion function suitable for the 147db96d56Sopenharmony_ci:mod:`readline` module by completing valid Python identifiers and keywords. 157db96d56Sopenharmony_ci 167db96d56Sopenharmony_ciWhen this module is imported on a Unix platform with the :mod:`readline` module 177db96d56Sopenharmony_ciavailable, an instance of the :class:`Completer` class is automatically created 187db96d56Sopenharmony_ciand its :meth:`complete` method is set as the :mod:`readline` completer. 197db96d56Sopenharmony_ci 207db96d56Sopenharmony_ciExample:: 217db96d56Sopenharmony_ci 227db96d56Sopenharmony_ci >>> import rlcompleter 237db96d56Sopenharmony_ci >>> import readline 247db96d56Sopenharmony_ci >>> readline.parse_and_bind("tab: complete") 257db96d56Sopenharmony_ci >>> readline. <TAB PRESSED> 267db96d56Sopenharmony_ci readline.__doc__ readline.get_line_buffer( readline.read_init_file( 277db96d56Sopenharmony_ci readline.__file__ readline.insert_text( readline.set_completer( 287db96d56Sopenharmony_ci readline.__name__ readline.parse_and_bind( 297db96d56Sopenharmony_ci >>> readline. 307db96d56Sopenharmony_ci 317db96d56Sopenharmony_ciThe :mod:`rlcompleter` module is designed for use with Python's 327db96d56Sopenharmony_ci:ref:`interactive mode <tut-interactive>`. Unless Python is run with the 337db96d56Sopenharmony_ci:option:`-S` option, the module is automatically imported and configured 347db96d56Sopenharmony_ci(see :ref:`rlcompleter-config`). 357db96d56Sopenharmony_ci 367db96d56Sopenharmony_ciOn platforms without :mod:`readline`, the :class:`Completer` class defined by 377db96d56Sopenharmony_cithis module can still be used for custom purposes. 387db96d56Sopenharmony_ci 397db96d56Sopenharmony_ci 407db96d56Sopenharmony_ci.. _completer-objects: 417db96d56Sopenharmony_ci 427db96d56Sopenharmony_ciCompleter Objects 437db96d56Sopenharmony_ci----------------- 447db96d56Sopenharmony_ci 457db96d56Sopenharmony_ciCompleter objects have the following method: 467db96d56Sopenharmony_ci 477db96d56Sopenharmony_ci 487db96d56Sopenharmony_ci.. method:: Completer.complete(text, state) 497db96d56Sopenharmony_ci 507db96d56Sopenharmony_ci Return the *state*\ th completion for *text*. 517db96d56Sopenharmony_ci 527db96d56Sopenharmony_ci If called for *text* that doesn't include a period character (``'.'``), it will 537db96d56Sopenharmony_ci complete from names currently defined in :mod:`__main__`, :mod:`builtins` and 547db96d56Sopenharmony_ci keywords (as defined by the :mod:`keyword` module). 557db96d56Sopenharmony_ci 567db96d56Sopenharmony_ci If called for a dotted name, it will try to evaluate anything without obvious 577db96d56Sopenharmony_ci side-effects (functions will not be evaluated, but it can generate calls to 587db96d56Sopenharmony_ci :meth:`__getattr__`) up to the last part, and find matches for the rest via the 597db96d56Sopenharmony_ci :func:`dir` function. Any exception raised during the evaluation of the 607db96d56Sopenharmony_ci expression is caught, silenced and :const:`None` is returned. 617db96d56Sopenharmony_ci 62