module ipythonhelper.magic_class

Inheritance diagram of pyquickhelper.ipythonhelper.magic_class

Short summary

module pyquickhelper.ipythonhelper.magic_class

Magic command to handle files

source on GitHub

Classes

class

truncated documentation

MagicClassWithHelpers

Provides some functions reused in others classes inherited from Magics. The class should not be registered as it is …

Properties

property

truncated documentation

Context

return the context or None

cross_validation_lock

A contextmanager for running a block with our cross validation lock set to True. At the end of the block, …

Methods

method

truncated documentation

add_context

add context to the class, mostly for debug purpose

get_args

parser a command line with a given parser

get_parser

returns a parser for a magic command, initialize it if it does not exists, it creates. The parsers are stored …

Documentation

Magic command to handle files

source on GitHub

class pyquickhelper.ipythonhelper.magic_class.MagicClassWithHelpers(shell=None, **kwargs)[source][source]

Bases: IPython.core.magic.Magics

Provides some functions reused in others classes inherited from Magics. The class should not be registered as it is but should be used as an ancestor for another class. It can be registered this way:

def register_file_magics():
    from IPython import get_ipython
    ip = get_ipython()
    ip.register_magics(MagicFile)

source on GitHub

Context[source]

return the context or None

source on GitHub

_parser_store = {}[source]
_trait_default_generators = {}[source]
add_context(context)[source][source]

add context to the class, mostly for debug purpose

Parameters

context – dictionary

source on GitHub

get_args(line, parser, print_function=<built-in function print>)[source][source]

parser a command line with a given parser

Parameters
  • line – string (command line)

  • parser – parser which has to be used to parse line

  • print_function – function to use to display the help

Returns

results

If the line cannot be parsed, the function displays the help using function print.

Example:

@line_magic
def custom_magic_command(self, line):
    parser = self.get_parser(MagicClass.custom_magic_command_parser, "custom_magic_command")
    args = self.get_args(line, parser)
    if args is not None:
        param = args.param

        # ....

source on GitHub

get_parser(parser_class, name)[source][source]

returns a parser for a magic command, initialize it if it does not exists, it creates. The parsers are stored in static member _parser_store.

Parameters
  • parser_class – the parser to use for this magic command

  • name – name of the static variable which will contain the parser

See method get_args

source on GitHub