Warning

You are reading the documentation related to the development version. Go here if you are looking for the documentation of the stable release.

spectrochempy.ipython.magics.SpectroChemPyMagics

class SpectroChemPyMagics(**kwargs)[source]

This class implements the addscript ipython magic function.

The ipython extensions`can be loaded via %load_ext spectrochempy.ipython or be configured to be autoloaded by IPython at startup time.

Create a configurable given a config config.

Parameters
  • config (Config) – If this is empty, default values are used. If config is a Config instance, it will be used to configure the instance.

  • parent (Configurable instance, optional) – The parent Configurable instance of this object.

Notes

Subclasses of Configurable must call the __init__ method of Configurable before doing anything else and using super:

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.

Attributes Summary

config

traitlets.config.Config object.

magics

registered

Methods Summary

addscript([pars, cell])

This works both as %addscript and as %%addscript.

arg_err(func)

Print docstring if incorrect arguments were passed

default_option(fn, optstr)

Make an entry in the options_table for fn, with value optstr

format_latex(strng)

Format a string for latex inclusion.

parse_options(arg_str, opt_str, *long_opts, **kw)

Parse options passed to an argument string.

Attributes Documentation

config

traitlets.config.Config object.

magics = {'cell': {'addscript': 'addscript'}, 'line': {'addscript': 'addscript'}}
registered = True

Methods Documentation

addscript(pars='', cell=None)[source]

This works both as %addscript and as %%addscript.

This magic command can either take a local filename, element in the namespace or history range (see %history), or the current cell content.

Usage:

%addscript -p project n1-n2 n3-n4 … n5 .. n6 …

or

%%addscript -p project …code lines …

Options:

-p <string>

Name of the project where the script will be stored. If not provided, a project with a standard name : proj is searched.

-o <string>

script name.

-s <symbols>

Specify function or classes to load from python source.

-a

append to the current script instead of overwriting it.

-n

Search symbol in the current namespace.

Examples

In[1]: %addscript myscript.py

In[2]: %addscript 7-27

In[3]: %addscript -s MyClass,myfunction myscript.py
In[4]: %addscript MyClass

In[5]: %addscript mymodule.myfunction
arg_err(func)[source]

Print docstring if incorrect arguments were passed

default_option(fn, optstr)[source]

Make an entry in the options_table for fn, with value optstr

format_latex(strng)[source]

Format a string for latex inclusion.

parse_options(arg_str, opt_str, *long_opts, **kw)[source]

Parse options passed to an argument string.

The interface is similar to that of getopt.getopt, but it returns a Struct with the options as keys and the stripped argument string still as a string.

arg_str is quoted as a true sys.argv vector by using shlex.split. This allows us to easily expand variables, glob files, quote arguments, etc.

Parameters
  • arg_str (str) – The arguments to parse.

  • opt_str (str) – The options specification.

  • mode (str, default ‘string’) – If given as ‘list’, the argument string is returned as a list (split on whitespace) instead of a string.

  • list_all (bool, default False) – Put all option values in lists. Normally only options appearing more than once are put in a list.

  • posix (bool, default True) – Whether to split the input line in POSIX mode or not, as per the conventions outlined in the shlex module from the standard library.

Examples using spectrochempy.ipython.magics.SpectroChemPyMagics