Is the list of Python reserved words and builtins available in a library? -


is list of python reserved words , builtins available in library? want like:

 x.y import reserved_words_and_builtins   if x in reserved_words_and_builtins:      x += '_' 

to verify string keyword can use keyword.iskeyword; list of reserved keywords can use keyword.kwlist:

>>> import keyword >>> keyword.iskeyword('break') true >>> keyword.kwlist ['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'] 

if want include built-in names (python 3), then:

>>> import builtins >>> dir(builtins) ['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', 'recursionerror', 'referenceerror',  'resourcewarning', 'runtimeerror', 'runtimewarning', 'stopasynciteration',  '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'] 

for python 2 you'll need use __builtin__ module

>>> import __builtin__ >>> dir(__builtin__) ['arithmeticerror', 'assertionerror', 'attributeerror', 'baseexception', 'buffererror', 'byteswarning', 'deprecationwarning', 'eoferror', 'ellipsis', 'environmenterror', 'exception', 'false', 'floatingpointerror', 'futurewarning', 'generatorexit', 'ioerror', 'importerror', 'importwarning', 'indentationerror', 'indexerror', 'keyerror', 'keyboardinterrupt', 'lookuperror', 'memoryerror', 'nameerror', 'none', 'notimplemented', 'notimplementederror', 'oserror', 'overflowerror', 'pendingdeprecationwarning', 'referenceerror', 'runtimeerror', 'runtimewarning', 'standarderror', 'stopiteration', 'syntaxerror', 'syntaxwarning', 'systemerror', 'systemexit', 'taberror', 'true', 'typeerror', 'unboundlocalerror', 'unicodedecodeerror', 'unicodeencodeerror', 'unicodeerror', 'unicodetranslateerror', 'unicodewarning', 'userwarning', 'valueerror', 'warning', 'windowserror', 'zerodivisionerror', '_', '__debug__', '__doc__', '__import__', '__name__', '__package__', 'abs', 'all', 'any', 'apply', 'basestring', 'bin', 'bool', 'buffer', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'cmp', 'coerce', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'execfile', 'exit', 'file', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'intern', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'long', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'raw_input', 'reduce', 'reload', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'unichr', 'unicode', 'vars', 'xrange', 'zip'] 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -