Magic commandsΒΆ
%codediff
It displays differences between two strings assuming they contains multiple lines. The magic command is equivalent to:
from IPython.core.display import display_html
from pyquickhelper.texthelper.edit_text_diff (
import edit_distance_text, diff2html)
_, aligned, final = edit_distance_text(
args.c1, args.c2, threshold=args.threshold,
verbose=args.verbose)
ht = diff2html(args.c1, args.c2, aligned, final)
display_html(ht)
(original entry : magic_class_diff.py:docstring of pyquickhelper.ipythonhelper.magic_class_diff.MagicDiff.codediff, line 1)
%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)
%strdiff
It displays differences between two strings assuming they contains multiple lines. The magic command is equivalent to:
from IPython.core.display import display_html
from pyquickhelper.texthelper.text_diff import html_diffs
html = html_diffs(<s1>, <s2>)
display_html(html)
(original entry : magic_class_diff.py:docstring of pyquickhelper.ipythonhelper.magic_class_diff.MagicDiff.strdiff, line 1)
%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)