module ipythonhelper.magic_parser

Inheritance diagram of pyquickhelper.ipythonhelper.magic_parser

Short summary

module pyquickhelper.ipythonhelper.magic_parser

Magic parser to parse magic commands

source on GitHub

Classes

class

truncated documentation

MagicCommandParser

Adds method parse_cmd to argparse.ArgumentParser.

Static Methods

staticmethod

truncated documentation

_private_get_name

guesses the name of a parameter knowning the argument given to add_argument()

Methods

method

truncated documentation

__init__

custom constructor, see argparse.ArgumentParser.

add_argument

Overloads the method, see ArgumentParser. Among the …

eval

Evaluate a string knowing the context, it returns value if it does not belong to the context or if it …

expected_eval_type

return the expected evaluation type for the parameter (if the value is interpreter as a python expression)

expected_type

Returns the expected type for the parameter.

has_choices

tells if a parameter has choises

has_eval

Tells if a parameter value should be consider as a variable or some python code to evaluate.

parse_cmd

split line using shlex and call parse_args

Documentation

Magic parser to parse magic commands

source on GitHub

class pyquickhelper.ipythonhelper.magic_parser.MagicCommandParser(prog, *l, **p)[source][source]

Bases: argparse.ArgumentParser

Adds method parse_cmd to argparse.ArgumentParser.

source on GitHub

custom constructor, see argparse.ArgumentParser.

Parameters
  • prog – command name

  • l – positional arguments

  • p – named arguments

source on GitHub

__init__(prog, *l, **p)[source][source]

custom constructor, see argparse.ArgumentParser.

Parameters
  • prog – command name

  • l – positional arguments

  • p – named arguments

source on GitHub

static _private_get_name(*args)[source][source]

guesses the name of a parameter knowning the argument given to add_argument

source on GitHub

add_argument(*args, **kwargs)[source][source]

Overloads the method, see ArgumentParser. Among the parameters:

  • no_eval: avoid considering the parameter value as a potential variable stored in the notebook workspace.

  • eval_type: type can be used for parsing and eval_type is the expected return type.

The method adds parameter no_eval to avoid considering the parameter value as a potential variable stored in the notebook workspace.

source on GitHub

eval(value, context, fLOG=<function noLOG>)[source][source]

Evaluate a string knowing the context, it returns value if it does not belong to the context or if it contains brackets or symbols (+, *), if the value cannot be evaluated (with function eval), it returns the value value

Parameters
  • value – string

  • context – something like self.shell.user_ns

  • fLOG – logging function

Returns

value or its evaluation

The method interprets variable inside list, tuple or dictionaries (for value).

source on GitHub

expected_eval_type(name)[source][source]

return the expected evaluation type for the parameter (if the value is interpreter as a python expression)

Parameters

name – parameter name

Returns

type or None of unknown

source on GitHub

expected_type(name)[source][source]

Returns the expected type for the parameter.

Parameters

name – parameter name

Returns

type or None of unknown

source on GitHub

has_choices(name)[source][source]

tells if a parameter has choises

Parameters

name – parameter name

Returns

boolean

source on GitHub

has_eval(name)[source][source]

Tells if a parameter value should be consider as a variable or some python code to evaluate.

Parameters

name – parameter name

Returns

boolean

source on GitHub

parse_cmd(line, context=None, fLOG=<function noLOG>)[source][source]

split line using shlex and call parse_args

Parameters
  • line – string

  • context – if not None, tries to evaluate expression the command may contain

  • fLOG – logging function

Returns

list of strings

The function distinguishes between the type used to parse the command line (type) and the expected type after the evaluation eval_type.

source on GitHub