This documentation covers IPython versions 6.0 and higher. Beginning with version 6.0, IPython stopped supporting compatibility with Python versions lower than 3.3 including all versions of Python 2.7.

If you are looking for an IPython version compatible with Python 2.7, please use the IPython 5.x LTS release and refer to its documentation (LTS is the long term support release).

Module: utils.tokenutil

Token-related utilities

3 Functions


wrap generate_tokens to catch EOF errors

IPython.utils.tokenutil.line_at_cursor(cell, cursor_pos=0)

Return the line in a cell at a given cursor position

Used for calling line-based APIs that don’t support multi-line input, yet.

  • cell (str) – multiline block of text
  • cursor_pos (integer) – the cursor position

(line, offset) – The line with the current cursor, and the character offset of the start of the line.

Return type:

(string, integer)

IPython.utils.tokenutil.token_at_cursor(cell, cursor_pos=0)

Get the token at a given cursor

Used for introspection.

Function calls are prioritized, so the token for the callable will be returned if the cursor is anywhere inside the call.

  • cell (unicode) – A block of Python code
  • cursor_pos (int) – The location of the cursor in the block where the token should be found