Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Python help (ST)
import sublime, sublime_plugin
help = {
'abs': 'Returns the absolute value of a number, or the magnitude of a complex number',
'all': 'Returns True if all elements of an iterable are true (or the iterable is empty)',
'any': 'Returns True if any of the elements of an iterable are true (False if the iterable is empty)',
'basestring': 'Superclass for str and unicode - used with isinstance function',
'bin': 'Converts an integer number to a binary string',
'bool': 'Converts a value to a Boolean, of False if no argument',
'bytearray': 'Returns a new array of bytes - a mutable sequence of integers 0-256',
'callable': 'Returns True if the object argument appears callable',
'chr': 'Returns a string of one character whose ASCII code is the integer argument 0-255',
'classmethod': 'Returns a class method for \'function\'. @classmethod is a function decorator',
'cmp': 'Compare objects, returning an integer',
'compile': 'Compile the source into a code or AST object. Code objects can be exec() or eval()',
'complex': 'Create a complex number - argument could be a string',
'delattr': '\'name\' is a string - equivalent to del \'object.attribute\'',
'dict': 'Create a new data dictionary, optionally with items from arg',
'dir': 'Without arguments, returns the list of names in the current local scope',
'divmod': 'Takes two (non complex) numbers and returns a pair of numbers consisting of ' +
'their quotient and remainder when using long division',
'enumerate': 'Returns an enumerate object',
'eval': 'The expression argument is parsed and evaluated as a Python expression',
'execfile': 'Similar to the exec statement, but parses a file instead of a string',
'file': 'Constructor function for the file type - open() is preferred',
'filter': 'Construct a list from those elements of iterable for which function returns true',
'float': 'Converts a string or a number to floating point',
'format': 'Converts a value to a formatted representation, as controlled by format_spec',
'frozenset': 'Returns an immutable, hashable set',
'getattr': 'Returns the value of the named attribute of \'object\' or the supplied default',
'globals': 'Returns a dictionary representing the current global symbol table',
'hasattr': 'The result is True if the name (a string) is the name of one of the object\'s attributes',
'hash': 'Return the hash value of the object (if it has one). Hash values are integers.',
'help': 'Invoke the built-in help system. (This function is intended for interactive use.)',
'hex': 'Converts an integer number to a hexadecimal string. The result is a valid Python expression.',
'id': 'Return the id of an object - an integer (or long integer) which is unique and constant for ' +
'this object during its lifetime.',
'__import__': '(Advanced) This function is invoked by the import statement',
'input': 'Equivalent to eval(raw_input(prompt)). Prefer raw_input() for general input from users.',
'int': 'Converts a string or number to a plain integer. Base defaults to 10 and can be 2-36.',
'isinstance': 'Return true if the object argument is an instance of the classinfo argument, or of ' +
'a (direct, indirect or virtual) subclass thereof.',
'issubclass': 'Returns true if class is a subclass (direct, indirect or virtual) of classinfo. ' +
'A class is considered a subclass of itself.',
'iter': 'Returns an iterator object. If sentinel is given then o must be a callable object.',
'len': 'Return the length (the number of items) of an object. The argument may be a sequence ' +
'(string, tuple or list) or a mapping (dictionary).',
'list': 'Returns a list whose items are the same and in the same order as iterable\'s items',
'locals': 'Returns a dictionary representing the current local symbol table',
'long': 'Converts a string or number to a long integer. Base defaults to 10 (2-36).',
'map': 'Apply function to every item of iterable(s) and return a list of the results.',
'max': 'Returns the largest item of an iterable or other arguments: max(a,b,c,key=func)',
'memoryview': 'Returns a \'memory view\' object created from the given argument',
'min': 'Returns the smallest item of an iterable or other arguments: min(a,b,c,key=func)',
'next': 'Retrieve the next item from the iterator by calling its next() method. If default ' +
'is given, it is returned if the iterator is exhausted.',
'object': 'Returns a new featureless object (no arguments)',
'oct': 'Converts an integer number to an octal string. The result is a valid Python expression.',
'open': 'Open a file, returning a file object. Mode \'r\' for reading, bufsize 0 for unbuffered.',
'ord': 'Returns an integer representing the Unicode code of the single character',
'pow': 'x to the power y (modulo z, if present). pow(x,y) is equivalent to x**y.',
'print': 'Print objects to a stream. Use \'from __future__ import print_function\' to disable the ' +
'print statement.',
'property': '(New-style classes) Returns a property attribute',
'range': 'Creates lists containing arithmetic progressions - most often used in for loops',
'raw_input': 'Reads a line from input - converting to a string (and removing trailing newline)',
'reduce': 'Applies function of two arguments cumulatively to the items of iterable, reducing ' +
'the iterable to a single value',
'reload': 'Reload a previously (successfully) loaded module',
'repr': 'Returns a string containing a printable representation of an object. See also __repr__()',
'reversed': 'Returns a reversed iterator. See also __reversed__()',
'round': 'Returns the floating point argument rounded to \'digits\' after the decimal point',
'set': 'Returns a set object - an unordered collection of distinct hashable objects',
'setattr': 'Equivalent to \'object.attribute = value\'',
'slice': 'Returns a \'slice\' object from the set of indices specified by range(start, stop, step)',
'sorted': 'Returns a new sorted list from the items in iterable. key=str.lower',
'staticmethod': 'Returns a static method for \'function\' - does not receive an implicit 1st argument',
'str': 'Returns a string representation of an object',
'sum': 'Sum an iterable from \'start\' (default 0)',
'super': '(New-style classes) Returns a proxy object that delegates method calls to a parent ' +
' or sibling class of type',
'tuple': 'Returns a tuple whose items are the same and in the same order as iterable\'s items',
'type': 'Returns the type of an object - with 3 arguments it is a constructor',
'unichr': 'Return the Unicode string of one character whose Unicode code is the integer argument',
'unicode': 'Return the Unicode string version of \'object\'',
'vars': 'Return the __dict__ attribute for a module, class, instance, or any other object ' +
' with a __dict__ attribute',
'xrange': 'Similar to range(), but returns an \'xrange object\' instead of a list',
'zip': 'Returns a list of tuples, where the i-th tuple contains the i-th element from each ' +
'of the argument sequences or iterables'
class PyHelpCommand(sublime_plugin.TextCommand):
def run(self, edit):
curr_view = self.view
if not curr_view.match_selector(0, 'source.python'): return
sel = curr_view.sel()[0]
pt = sel.end()
word_r = curr_view.word(pt)
word = curr_view.substr(word_r).lower()
sublime.status_message(help.get(word, 'No help available'))

agibsonsw commented Mar 13, 2012

Help for Python functions in Sublime Text. Add a key-binding such as:

{ "keys": ["shift+f1"], "command": "py_help" }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment