Pythonã®codeã¢ã¸ã¥ã¼ã«ã使ãã¨ãä»»æã®ã¿ã¤ãã³ã°ã§å¯¾è©±ã³ã³ã½ã¼ã«ãèµ·åã§ããã
readlineãrlcompleterã¢ã¸ã¥ã¼ã«ã使ããã¨ã§ã対話ã³ã³ã½ã¼ã«å®è¡æã«è£å®ãæå¹ã«ãããã¨ãã§ããã
以ä¸ããµã³ãã«ã³ã¼ãã
console.py
# coding: utf-8 import code import readline import rlcompleter def hello(): print("Hello, world!") def main(): print(u"対話ã³ã³ã½ã¼ã«ãèµ·åãã¾ã...") # ã³ã³ã½ã¼ã«èµ·åæã®å¤æ°ãç¨æ variables = globals() # Tabã«ããè£å®ãæå¹ã«ãã readline.set_completer(rlcompleter.Completer(variables).complete) readline.parse_and_bind("tab:complete") # 対話ã³ã³ã½ã¼ã«ãéå§ code.interact(local=variables) if __name__ == '__main__': main()
å®è¡çµæ
$ python console.py 対話ã³ã³ã½ã¼ã«ãèµ·åãã¾ã... Python 2.7.3 (default, Apr 20 2012, 22:39:59) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> hello() Hello, world! >>>