module ipythonhelper.magic_class
¶
Short summary¶
module pyquickhelper.ipythonhelper.magic_class
Magic command to handle files
Classes¶
class |
truncated documentation |
---|---|
Provides some functions reused in others classes inherited from Magics. The class should not be registered as it is … |
Properties¶
property |
truncated documentation |
---|---|
return the context or None |
|
|
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 to the class, mostly for debug purpose |
|
parser a command line with a given parser |
|
Returns a parser for a magic command, initializes it if it does not exists, it creates it. The parsers are stored … |
Documentation¶
Magic command to handle files
- class pyquickhelper.ipythonhelper.magic_class.MagicClassWithHelpers(**kwargs: Any)[source]¶
Bases:
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)
Create a configurable given a config config.
Parameters¶
- configConfig
If this is empty, default values are used. If config is a
Config
instance, it will be used to configure the instance.- parentConfigurable instance, optional
The parent Configurable instance of this object.
Notes¶
Subclasses of Configurable must call the
__init__()
method ofConfigurable
before doing anything else and usingsuper()
:class MyConfigurable(Configurable): def __init__(self, config=None): super(MyConfigurable, self).__init__(config=config) # Then any other code you need to finish initialization.
This ensures that instances will be configured properly.
- _all_trait_default_generators: Dict[str, Any] = {'config': <bound method TraitType.default of <traitlets.traitlets.Instance object>>, 'parent': <bound method TraitType.default of <traitlets.traitlets.Instance object>>}[source]¶
- _descriptors = [<traitlets.traitlets.ObserveHandler object>, <traitlets.traitlets.Instance object>, <traitlets.traitlets.Instance object>][source]¶
- _instance_inits = [<bound method ObserveHandler.instance_init of <traitlets.traitlets.ObserveHandler object>>, <bound method Instance.instance_init of <traitlets.traitlets.Instance object>>, <bound method Instance.instance_init of <traitlets.traitlets.Instance object>>][source]¶
- _traits: Dict[str, Any] = {'config': <traitlets.traitlets.Instance object>, 'parent': <traitlets.traitlets.Instance object>}[source]¶
- add_context(context)[source]¶
add context to the class, mostly for debug purpose
- Parameters:
context – dictionary
- get_args(line, parser, print_function=<built-in function print>)[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 # ....
- get_parser(parser_class, name)[source]¶
Returns a parser for a magic command, initializes it if it does not exists, it creates it. 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