Magic commandsΒΆ

  1. %compress
  2. %decrypt_file
  3. %encrypt_file
  4. %htmlhelp
  5. %textdiff

%compress

It compresses a list of files, it returns the number of compressed files:

from pyquickhelper import zip_files, gzip_files, zip7_files
if format == "zip":
    zip_files(dest, files)
elif format == "gzip":
    gzip_files(dest, files)
elif format == "7z":
    zip7_files(dest, files)
else:
    raise ValueError("unexpected format: " + format)

(original entry : magic_class_compress.py:docstring of pyquickhelper.ipythonhelper.magic_class_compress.MagicCompress.compress, line 1)

%decrypt_file

The magic command is equivalent to:

from pyquickhelper.filehelper import decrypt_stream

password = "password"
source = "file source"
dest = "file destination"

if isinstance(password, str):
    password = bytes(password, encoding="ascii")

decrypt_stream(key=password, filename=source, out_filename=dest,
               chunksize=os.stat(source).st_size * 2 + 1)

(original entry : magic_class_crypt.py:docstring of pyquickhelper.ipythonhelper.magic_class_crypt.MagicCrypt.decrypt_file, line 1)

%encrypt_file

The magic command is equivalent to:

from pyquickhelper.filehelper import encrypt_stream

password = "password"
source = "file source"
dest = "file destination"

if isinstance(password, str):
    password = bytes(password, encoding="ascii")

encrypt_stream(key=password, filename=source, out_filename=dest,
               chunksize=os.stat(source).st_size * 2 + 1)

(original entry : magic_class_crypt.py:docstring of pyquickhelper.ipythonhelper.magic_class_crypt.MagicCrypt.encrypt_file, line 1)

%htmlhelp

Magic command htmlhelp convert docstring (RST) into HTML format for a better display in a notebook. It is equivalent to the code:

from pyquickhelper.helpgen import docstring2html
obj = <function or object>
docstring2html(obj, format="html")

See function docstring2html.

(original entry : magic_class_example.py:docstring of pyquickhelper.ipythonhelper.magic_class_example.MagicClassExample.htmlhelp, line 3)

%textdiff

It displays differences between two text files, two strings, two urls, it is based on create_visual_diff_through_html_files. Check blog post Visualize differences between two files in a notebook to see an example. See also A magic command to visualize differences between two files in a notebook. The magic command is equivalent to:

from IPython.core.display import display_html, display_javascript
from pyquickhelper import docstring2html, create_visual_diff_through_html_files
html, js = create_visual_diff_through_html_files(<f1>, <f2>,
                encoding=<encoding>, notebook=True,
                context_size=None if <context> in [None, ""] else int(<context>),
                inline_view=<inline>)
display_html(html)
display_javascript(js)

(original entry : magic_class_diff.py:docstring of pyquickhelper.ipythonhelper.magic_class_diff.MagicDiff.textdiff, line 1)