Hace poco estuve incluyendo autocompletado de código Python3 en un editor online (pyschool.net) destinado a la educación que se está desarrollando dentro del proyecto Brython.
El editor online que se usa es Ace (el notebook de IPython usa codemirror). El modo Python de Ace incluye palabras de Python2 y Brython implementa Python3 por lo que el resaltado de código y autocompletado oficial incluido con Ace no se ajusta a lo que se quería usar en pyschool.net. Para solventar esto creé el modo Python3 que se usa en el editor online (y que próximamente también podréis ver y usar en el editor oficial en Brython.info). Pero había que saber qué palabras incluir en el resaltado y autocompletado de Ace (ya estoy llegando a lo que quería mostrar). Y como Python es tan increible y tiene módulos para todo podéis hacer lo siguiente para obtener las palabras clave (keywords):
import keyword
print(keyword.kwlist)
Que dará como resultado:
['False', 'None', 'True', 'and', 'as', 'assert',
'break', 'class', 'continue', 'def', 'del', 'elif',
'else', 'except', 'finally', 'for', 'from', 'global',
'if', 'import', 'in', 'is', 'lambda', 'nonlocal',
'not', 'or', 'pass', 'raise', 'return', 'try',
'while', 'with', 'yield']
Y podéis obtener las funciones integradas (builtins) usando:
import builtins
print(dir(builtins))
Que dará como resultado:
['ArithmeticError', 'AssertionError', 'AttributeError',
'BaseException', 'BlockingIOError', 'BrokenPipeError', 'BufferError',
'BytesWarning', 'ChildProcessError', 'ConnectionAbortedError', 'ConnectionError',
'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning', 'EOFError',
'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FileExistsError',
'FileNotFoundError', 'FloatingPointError', 'FutureWarning', 'GeneratorExit',
'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError',
'InterruptedError', 'IsADirectoryError', 'KeyError', 'KeyboardInterrupt',
'LookupError', 'MemoryError', 'NameError', 'None', 'NotADirectoryError',
'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError',
'PendingDeprecationWarning', 'PermissionError', 'ProcessLookupError',
'ReferenceError', 'ResourceWarning', 'RuntimeError', 'RuntimeWarning',
'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit',
'TabError', 'TimeoutError', 'True', 'TypeError', 'UnboundLocalError',
'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError',
'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'ZeroDivisionError',
'__build_class__', '__debug__', '__doc__', '__import__', '__loader__', '__name__',
'__package__', '__spec__', 'abs', 'all', 'any', 'ascii', 'bin', 'bool', 'bytearray',
'bytes', 'callable', 'chr', 'classmethod', 'compile', 'complex', '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', 'property', 'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr',
'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip']
Limpio, fácil, rápido. Es tan eficiente que me ha sobrado tiempo para escribir esta entrada!!!
Espero que a alguien le sirva en algún momento.
Saludos.
P.D.: Si alguien quiere incluir el modo Python3 que hemos incluido en Ace dentro de Brython lo puede encontrar aquí.
Pybonacci