module ipythonhelper.magic_parser
¶
Classes¶
class |
truncated documentation |
---|---|
Adds method |
Static Methods¶
staticmethod |
truncated documentation |
---|---|
guesses the name of a parameter knowning the argument given to |
Methods¶
method |
truncated documentation |
---|---|
custom constructor, see argparse.ArgumentParser. |
|
Overloads the method, see ArgumentParser. Among the … |
|
Evaluate a string knowing the context, it returns value if it does not belong to the context or if it … |
|
return the expected evaluation type for the parameter (if the value is interpreter as a python expression) |
|
Returns the expected type for the parameter. |
|
tells if a parameter has choises |
|
Tells if a parameter value should be consider as a variable or some python code to evaluate. |
|
split line using shlex and call parse_args … |
Documentation¶
Magic parser to parse magic commands
-
class
pyquickhelper.ipythonhelper.magic_parser.
MagicCommandParser
(prog, *l, **p)[source][source]¶ Bases:
argparse.ArgumentParser
Adds method
parse_cmd
to argparse.ArgumentParser.custom constructor, see argparse.ArgumentParser.
- Parameters
prog – command name
l – positional arguments
p – named arguments
-
__init__
(prog, *l, **p)[source][source]¶ custom constructor, see argparse.ArgumentParser.
- Parameters
prog – command name
l – positional arguments
p – named arguments
-
static
_private_get_name
(*args)[source][source]¶ guesses the name of a parameter knowning the argument given to
add_argument
-
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.
-
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).
-
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
-
expected_type
(name)[source][source]¶ Returns the expected type for the parameter.
- Parameters
name – parameter name
- Returns
type or None of unknown
-
has_choices
(name)[source][source]¶ tells if a parameter has choises
- Parameters
name – parameter name
- Returns
boolean
-
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
-
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.