module filehelper.magic_file

Inheritance diagram of pyensae.filehelper.magic_file

Short summary

module pyensae.filehelper.magic_file

Magic command to handle files

source on GitHub

Classes

class truncated documentation
MagicFile Defines magic commands to help with files

Functions

function truncated documentation
register_file_magics register magics function, can be called from a notebook

Properties

property truncated documentation
Context return the context or None
cross_validation_lock A contextmanager for running a block with our cross validation lock set to True. At the end of the block, …

Static Methods

staticmethod truncated documentation
encoding_parser Defines the way to parse the magic command %encoding.
grep_parser defines the way to parse the magic command %grep
head_parser defines the way to parse the magic command %head
hhelp_parser Defines the way to parse the magic command %hhelp.
lsr_parser defines the way to parse the magic command %lsr
lsrepo_parser Defines the way to parse the magic command %lsrepo.
PYTHON_parser Defines the way to parse the magic command %%PYTHON.
runpy_parser Defines the way to parse the magic command %%runpy.
tail_parser defines the way to parse the magic command %tail

Methods

method truncated documentation
encoding Defines %encoding which guesses the encoding.
grep defines %grep which displays the first lines of a file
head Defines %head which displays the first lines of a file.
hhelp Define %hhelp, it displays the help for an object in HTML.
lsr Defines %lsr which returns the content of a folder, the method stops after around 10000 files –> you …
lsrepo Defines %lsrepo.
PYTHON Defines command %%PYTHON.
runpy Defines command %%runpy.
tail defines %tail which displays the last lines of a file

Documentation

Magic command to handle files

source on GitHub

class pyensae.filehelper.magic_file.MagicFile(shell=None, **kwargs)[source]

Bases: pyquickhelper.ipythonhelper.magic_class.MagicClassWithHelpers

Defines magic commands to help with files

Magic command not found

Magic commands are automatically added when importing the module:

import pyensae

This instruction does not raise any exception. To understand what went wrong, the following instruction must be run:

%load_ext pyensae

Usually, one necessary module is missing.

New in version 1.1.

source on GitHub

PYTHON(line, cell=None)[source]

Defines command %%PYTHON.

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", ""))

source on GitHub

static PYTHON_parser()[source]

Defines the way to parse the magic command %%PYTHON.

source on GitHub

_trait_default_generators = {}
encoding(line)[source]

Defines %encoding which guesses the encoding.

encoding

The magic command %encoding is equivalent to:

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

source on GitHub

static encoding_parser()[source]

Defines the way to parse the magic command %encoding.

source on GitHub

grep(line)[source]

defines %grep which displays the first lines of a file

grep

The magic command %grep is equivalent to:

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

source on GitHub

static grep_parser()[source]

defines the way to parse the magic command %grep

source on GitHub

head(line)[source]

Defines %head which displays the first lines of a file.

head

The magic command %head is equivalent to:

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

source on GitHub

static head_parser()[source]

defines the way to parse the magic command %head

source on GitHub

hhelp(line)[source]

Define %hhelp, it displays the help for an object in HTML.

hhelp

The magic command is equivalent to:

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

New in version 1.1.

source on GitHub

static hhelp_parser()[source]

Defines the way to parse the magic command %hhelp.

New in version 1.1.

source on GitHub

lsr(line)[source]

Defines %lsr which returns the content of a folder, the method stops after around 10000 files –> you should precise the filter.

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)

source on GitHub

static lsr_parser()[source]

defines the way to parse the magic command %lsr

source on GitHub

lsrepo(line)[source]

Defines %lsrepo.

lsrepo

The method returns the files present in a repository (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)

New in version 1.1.

source on GitHub

static lsrepo_parser()[source]

Defines the way to parse the magic command %lsrepo.

source on GitHub

runpy(line, cell=None)[source]

Defines command %%runpy.

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)

New in version 1.1.

source on GitHub

static runpy_parser()[source]

Defines the way to parse the magic command %%runpy.

source on GitHub

tail(line)[source]

defines %tail which displays the last lines of a file

tail

The magic command %tail is equivalent to:

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

source on GitHub

static tail_parser()[source]

defines the way to parse the magic command %tail

source on GitHub

pyensae.filehelper.magic_file.register_file_magics(ip=None)[source]

register magics function, can be called from a notebook

Parameters:ip – from get_ipython()

source on GitHub