Magic commands

Azure

Files

  1. encoding

  2. grep

  3. head

  4. lsr

  5. lsrepo

  6. tail

encoding

The magic command %encoding is equivalent to:

from pyensae.file_helper import file_head
file_head(<filename>, <n>, <encoding>)

(original entry : magic_file.py:docstring of pyensae.filehelper.magic_file.MagicFile.encoding, line 4)

grep

The magic command %grep is equivalent to:

from pyensae.file_helper import enumerate_grep
list(enumerate_grep(<filename>, <regex>, <encoding>))

(original entry : magic_file.py:docstring of pyensae.filehelper.magic_file.MagicFile.grep, line 4)

head

The magic command %head is equivalent to:

from pyensae.file_helper import file_head
file_head(<filename>, <n>, <encoding>)

(original entry : magic_file.py:docstring of pyensae.filehelper.magic_file.MagicFile.head, line 4)

lsr

The magic command %lsr is almost equivalent to:

from pyquickhelper.file_helper import explore_folder_iterfile
res = explore_folder_iterfile(<filename>, <pattern>)
for f in res:
    print(f)

(original entry : magic_file.py:docstring of pyensae.filehelper.magic_file.MagicFile.lsr, line 5)

lsrepo

The method returns the files present in a repository (:epkg:`GIT` or :pkg:`SVN`). The code is equivalent to:

from pyquickhelper.filehelper import explore_folder_iterfile_repo
res = explore_folder_iterfile_repo(<filename>, <pattern>)
for f in res:
    print(f)

(original entry : magic_file.py:docstring of pyensae.filehelper.magic_file.MagicFile.lsrepo, line 3)

tail

The magic command %tail is equivalent to:

from pyensae.file_helper import file_tail
file_tail(<filename>, <n>, <encoding>)

(original entry : magic_file.py:docstring of pyensae.filehelper.magic_file.MagicFile.tail, line 4)

Hadoop

Python

  1. PYTHON

  2. hhelp

  3. jsdf

  4. mpl_style

  5. nb_menu

  6. runpy

PYTHON

The magic command %%PYTHON is almost to:

with open(<filename>, "w", encoding="utf8") as f:
    f.write("# -*- coding: utf8 -*-\n")
    f.write(cell.replace("\r", ""))

(original entry : magic_file.py:docstring of pyensae.filehelper.magic_file.MagicFile.PYTHON, line 3)

hhelp

The magic command is equivalent to:

from pyquickhelper import docstring2html
docstring2html(obj, format=format)

(original entry : magic_file.py:docstring of pyensae.filehelper.magic_file.MagicFile.hhelp, line 3)

jsdf

The magic command %jsdf displays a dataframe using qgrid module. The code is the following:

import qgrid
if firt_call:
    qgrid.set_defaults(precision=<precision>)
    self.first_jsdf_call = False

df = args.df
grid_options = dict(defaultColumnWidth=<defaultColumnWidth>,
                    enableColumnReorder=<enableColumnReorder>,
                    multiColumnSort=<multiColumnSort>,
                    rowHeight=<rowHeight>,
                    showHeaderRow=<showHeaderRow>,
                    forceFitColumns=<forceFitColumns>,
                    autoHeight=<autoHeight>,
                    enableCellNavigation=<enableCellNavigation>)
qgrid.show_grid(df, grid_options=grid_options)

(original entry : magic_notebook.py:docstring of pyensae.notebookhelper.magic_notebook.MagicNotebook.jsdf, line 4)

mpl_style

This magic just does:

import matplotlib.pyplot as plt
plt.style.use('ggplot')

It should take place at the beginning of the notebook.

(original entry : magic_graph.py:docstring of pyensae.graphhelper.magic_graph.MagicGraph.mpl_style, line 4)

nb_menu

The magic command %nb_menu displays a menu in a notebook. It parses a notebook and displays a menu gathering all sections within that notebook. The code is the following:

from pyquickhelper.ipythonhelper import add_notebook_menu
js = add_notebook_menu(menu_id=<menu_id>, header=<title>, format=<format>,
                    first_level=<level1>, last_level=<level2>,
                    raw=<raw>)

(original entry : magic_notebook.py:docstring of pyensae.notebookhelper.magic_notebook.MagicNotebook.nb_menu, line 4)

runpy

%%runpy runs a python script which accepts standards input and produces standard outputs, a timeout is set up at 10s. It is almost equivalent to:

from pyquickhelper.loghelper import run_cmd
import sys
cmd = sys.executable.replace(
    "pythonw",
    "python") + " " + filename + " " + args
out, err = run_cmd(
    cmd, wait=True, sin=cell, communicate=True, timeout=10, shell=False)

(original entry : magic_file.py:docstring of pyensae.filehelper.magic_file.MagicFile.runpy, line 3)

SQL

  1. SQL

  2. SQL_add_function

  3. SQL_close

  4. SQL_connect_parser

  5. SQL_drop_table

  6. SQL_import_df

  7. SQL_import_tsv

  8. SQL_schema

  9. SQL_tables

SQL

The code for magic command %%SQL is equivalent to:

<variable> = db.execute(<cell>)

See notebook SQL Magic Commands with SQLite in a Notebook.

(original entry : magic_sql.py:docstring of pyensae.sql.magic_sql.MagicSQL.SQL, line 3)

SQL_add_function

The code for magic command %SQL_add_function is equivalent to:

db.add_function(fu)

See notebook SQL Magic Commands with SQLite in a Notebook.

(original entry : magic_sql.py:docstring of pyensae.sql.magic_sql.MagicSQL.SQL_add_function, line 3)

SQL_close

The code for magic command %SQL_close is equivalent to:

db.close()

See notebook SQL Magic Commands with SQLite in a Notebook.

(original entry : magic_sql.py:docstring of pyensae.sql.magic_sql.MagicSQL.SQL_close, line 3)

SQL_connect_parser

The code for magic command %SQL_connect_parser is equivalent to:

from pyense.sql import InterfaceSQL
obj = InterfaceSQL.create(args.filename)
obj.connect()

See notebook SQL Magic Commands with SQLite in a Notebook.

(original entry : magic_sql.py:docstring of pyensae.sql.magic_sql.MagicSQL.SQL_connect, line 4)

SQL_drop_table

The code for magic command %SQL_drop_table is equivalent to:

db.drop_table()

See notebook SQL Magic Commands with SQLite in a Notebook.

(original entry : magic_sql.py:docstring of pyensae.sql.magic_sql.MagicSQL.SQL_drop_table, line 3)

SQL_import_df

The code for magic command %SQL_import_df is equivalent to:

db.import_dataframe(<table>, <df>)

See notebook SQL Magic Commands with SQLite in a Notebook.

(original entry : magic_sql.py:docstring of pyensae.sql.magic_sql.MagicSQL.SQL_import_df, line 3)

SQL_import_tsv

The code for magic command %SQL_import_tsv is equivalent to:

db.import_flat_file(<filename>, <table>)

See notebook SQL Magic Commands with SQLite in a Notebook.

(original entry : magic_sql.py:docstring of pyensae.sql.magic_sql.MagicSQL.SQL_import_tsv, line 3)

SQL_schema

The code for magic command %SQL_schema is equivalent to:

db.get_table_columns(<table>, as_dict=not <as_list>)

See notebook SQL Magic Commands with SQLite in a Notebook.

(original entry : magic_sql.py:docstring of pyensae.sql.magic_sql.MagicSQL.SQL_schema, line 3)

SQL_tables

The code for magic command %SQL_tables is equivalent to:

db.get_table_list()

See notebook SQL Magic Commands with SQLite in a Notebook.

(original entry : magic_sql.py:docstring of pyensae.sql.magic_sql.MagicSQL.SQL_tables, line 3)