En fait, je ne comprends pas complètement le principe de fonctionnement de Completer, en particulier la partie state. J'espère que quelqu'un pourra l'expliquer. Merci beaucoup !
http://stackoverflow.com/ques... Ce code est bien écrit Si vous souhaitez compléter le deuxième paramètre, vous devez écrire votre propre fonction complète similaire au code suivant.
def complete_cd(self, *args):
cwd = CURRENT_PATH
results = [c for c in os.listdir(cwd) if c.startswith(args[0][0])]
return results
ps : Le document officiel dit :
Note The underlying Readline library API may be implemented by the libedit library instead of GNU readline. On MacOS X the readline module detects which library is being used at run time.
The configuration file for libedit is different from that of GNU readline. If you programmatically load configuration strings you can check for the text “libedit” in readline.__doc__ to differentiate between GNU readline and libedit.
所以在 MAC 和 Windows 上面不适用
Si vous souhaitez l'utiliser sur toutes les plateformes (Windows n'est pas testé), utilisez le code de chargement suivant
try:
import readline
except ImportError:
try:
import pyreadline as readline
# throw open a browser if we fail both readline and pyreadline
except ImportError:
import webbrowser
webbrowser.open("http://ipython.scipy.org/moin/PyReadline/Intro#line-36")
# throw open a browser
#pass
else:
import rlcompleter
if(sys.platform == 'darwin'):
readline.parse_and_bind ("bind ^I rl_complete")
else:
readline.parse_and_bind("tab: complete")
Lancer des briques
Utilisez readline, voici un exemple simple :
Test :
python - ligne de lecture
Bibliothèque GNU Readline
Présentation du jade
En fait, je ne comprends pas complètement le principe de fonctionnement de Completer, en particulier la partie
state
. J'espère que quelqu'un pourra l'expliquer. Merci beaucoup !Questions auxquelles j'ai répondu : Python-QA
http://stackoverflow.com/ques...
Ce code est bien écrit Si vous souhaitez compléter le deuxième paramètre, vous devez écrire votre propre fonction complète similaire au code suivant.
ps : Le document officiel dit :
Si vous souhaitez l'utiliser sur toutes les plateformes (Windows n'est pas testé), utilisez le code de chargement suivant