IPython Documentation

Table Of Contents

Previous topic

core.profiledir

Next topic

core.pylabtools

This Page

core.prompts

Module: core.prompts

Inheritance diagram for IPython.core.prompts:

Classes for handling input/output prompts.

Authors:

  • Fernando Perez
  • Brian Granger
  • Thomas Kluyver

Classes

LazyEvaluate

class IPython.core.prompts.LazyEvaluate(func, *args, **kwargs)

Bases: object

This is used for formatting strings with values that need to be updated at that time, such as the current time or working directory.

__init__(func, *args, **kwargs)

PromptManager

class IPython.core.prompts.PromptManager(shell, config=None)

Bases: IPython.config.configurable.Configurable

This is the primary interface for producing IPython’s prompts.

__init__(shell, config=None)
classmethod class_config_section()

Get the config class config section

classmethod class_get_help(inst=None)

Get the help string for this class in ReST format.

If inst is given, it’s current trait values will be used in place of class defaults.

classmethod class_get_trait_help(trait, inst=None)

Get the help string for a single trait.

If inst is given, it’s current trait values will be used in place of the class default.

classmethod class_print_help(inst=None)

Get the help string for a single trait and print it.

classmethod class_trait_names(**metadata)

Get a list of all the names of this classes traits.

This method is just like the trait_names() method, but is unbound.

classmethod class_traits(**metadata)

Get a list of all the traits of this class.

This method is just like the traits() method, but is unbound.

The TraitTypes returned don’t know anything about the values that the various HasTrait’s instances are holding.

This follows the same algorithm as traits does and does not allow for any simple way of specifying merely that a metadata name exists, but has any value. This is because get_metadata returns None if a metadata key doesn’t exist.

color_scheme

A trait for unicode strings.

color_scheme_table

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

config

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

created = None
in2_template

A trait for unicode strings.

in_template

A trait for unicode strings.

invisible_chars

An instance of a Python dict.

justify

A boolean (True, False) trait.

lazy_evaluate_fields

An instance of a Python dict.

on_trait_change(handler, name=None, remove=False)

Setup a handler to be called when a trait changes.

This is used to setup dynamic notifications of trait changes.

Static handlers can be created by creating methods on a HasTraits subclass with the naming convention ‘_[traitname]_changed’. Thus, to create static handler for the trait ‘a’, create the method _a_changed(self, name, old, new) (fewer arguments can be used, see below).

Parameters :

handler : callable

A callable that is called when a trait changes. Its signature can be handler(), handler(name), handler(name, new) or handler(name, old, new).

name : list, str, None

If None, the handler will apply to all traits. If a list of str, handler will apply to all names in the list. If a str, the handler will apply just to that name.

remove : bool

If False (the default), then install the handler. If True then unintall it.

out_template

A trait for unicode strings.

render(name, color=True, just=None, **kwargs)

Render the selected prompt.

Parameters :

name : str

Which prompt to render. One of ‘in’, ‘in2’, ‘out’, ‘rewrite’

color : bool

If True (default), include ANSI escape sequences for a coloured prompt.

just : bool

If True, justify the prompt to the width of the last prompt. The default is stored in self.justify.

**kwargs : :

Additional arguments will be passed to the string formatting operation, so they can override the values that would otherwise fill in the template.

Returns :

A string containing the rendered prompt. :

shell

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

templates

An instance of a Python dict.

trait_metadata(traitname, key)

Get metadata values for trait by key.

trait_names(**metadata)

Get a list of all the names of this classes traits.

traits(**metadata)

Get a list of all the traits of this class.

The TraitTypes returned don’t know anything about the values that the various HasTrait’s instances are holding.

This follows the same algorithm as traits does and does not allow for any simple way of specifying merely that a metadata name exists, but has any value. This is because get_metadata returns None if a metadata key doesn’t exist.

txtwidth

An int trait.

update_config(config)

Fire the traits events when the config is updated.

update_prompt(name, new_template=None)

This is called when a prompt template is updated. It processes abbreviations used in the prompt template (like #) and calculates how many invisible characters (ANSI colour escapes) the resulting prompt contains.

It is also called for each prompt on changing the colour scheme. In both cases, traitlets should take care of calling this automatically.

width

An int trait.

UserNSFormatter

class IPython.core.prompts.UserNSFormatter(shell)

Bases: string.Formatter

A Formatter that falls back on a shell’s user_ns and __builtins__ for name resolution

__init__(shell)
check_unused_args(used_args, args, kwargs)
convert_field(value, conversion)
format(format_string, *args, **kwargs)
format_field(value, format_spec)
get_field(field_name, args, kwargs)
get_value(key, args, kwargs)
parse(format_string)
vformat(format_string, args, kwargs)

Functions

IPython.core.prompts.cwd_filt(depth)

Return the last depth elements of the current working directory.

$HOME is always replaced with ‘~’. If depth==0, the full path is returned.

IPython.core.prompts.cwd_filt2(depth)

Return the last depth elements of the current working directory.

$HOME is always replaced with ‘~’. If depth==0, the full path is returned.

IPython.core.prompts.multiple_replace(dict, text)

Replace in ‘text’ all occurences of any key in the given dictionary by its corresponding value. Returns the new string.