module filehelper.magic_file
¶
Short summary¶
module pyensae.filehelper.magic_file
Magic command to handle files
Classes¶
class |
truncated documentation |
---|---|
Defines magic commands to help with files |
Functions¶
function |
truncated documentation |
---|---|
register magics function, can be called from a notebook |
Properties¶
property |
truncated documentation |
---|---|
|
return the context or None |
|
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 |
---|---|
Defines the way to parse the magic command |
|
defines the way to parse the magic command |
|
defines the way to parse the magic command |
|
Defines the way to parse the magic command |
|
defines the way to parse the magic command |
|
Defines the way to parse the magic command |
|
Defines the way to parse the magic command |
|
Defines the way to parse the magic command |
|
defines the way to parse the magic command |
Methods¶
method |
truncated documentation |
---|---|
Defines |
|
defines |
|
Defines |
|
Define |
|
Defines |
|
Defines |
|
Defines command |
|
Defines command |
|
defines |
Documentation¶
Magic command to handle files
- class pyensae.filehelper.magic_file.MagicFile(**kwargs: Any)¶
Bases:
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.
Create a configurable given a config config.
Parameters¶
- configConfig
If this is empty, default values are used. If config is a
Config
instance, it will be used to configure the instance.- parentConfigurable instance, optional
The parent Configurable instance of this object.
Notes¶
Subclasses of Configurable must call the
__init__()
method ofConfigurable
before doing anything else and usingsuper()
: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.
- PYTHON(line, cell=None)¶
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", ""))
- static PYTHON_parser()¶
Defines the way to parse the magic command
%%PYTHON
.
- _all_trait_default_generators: Dict[str, Any] = {'config': <bound method TraitType.default of <traitlets.traitlets.Instance object>>, 'parent': <bound method TraitType.default of <traitlets.traitlets.Instance object>>}¶
- _descriptors = [<traitlets.traitlets.ObserveHandler object>, <traitlets.traitlets.Instance object>, <traitlets.traitlets.Instance object>]¶
- _instance_inits = [<bound method ObserveHandler.instance_init of <traitlets.traitlets.ObserveHandler object>>, <bound method Instance.instance_init of <traitlets.traitlets.Instance object>>, <bound method Instance.instance_init of <traitlets.traitlets.Instance object>>]¶
- _trait_default_generators = {}¶
- _traits: Dict[str, Any] = {'config': <traitlets.traitlets.Instance object>, 'parent': <traitlets.traitlets.Instance object>}¶
- encoding(line)¶
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>)
- static encoding_parser()¶
Defines the way to parse the magic command
%encoding
.
- grep(line)¶
defines
%grep
which displays the first lines of a filegrep
The magic command
%grep
is equivalent to:from pyensae.file_helper import enumerate_grep list(enumerate_grep(<filename>, <regex>, <encoding>))
- static grep_parser()¶
defines the way to parse the magic command
%grep
- head(line)¶
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>)
- static head_parser()¶
defines the way to parse the magic command
%head
- hhelp(line)¶
Define
%hhelp
, it displays the help for an object in :epkg:`HTML`.hhelp
The magic command is equivalent to:
from pyquickhelper import docstring2html docstring2html(obj, format=format)
New in version 1.1.
- static hhelp_parser()¶
Defines the way to parse the magic command
%hhelp
.New in version 1.1.
- lsr(line)¶
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)
- static lsr_parser()¶
defines the way to parse the magic command
%lsr
- lsrepo(line)¶
Defines
%lsrepo
.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)
New in version 1.1.
- static lsrepo_parser()¶
Defines the way to parse the magic command
%lsrepo
.
- runpy(line, cell=None)¶
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.
- static runpy_parser()¶
Defines the way to parse the magic command
%%runpy
.
- tail(line)¶
defines
%tail
which displays the last lines of a filetail
The magic command
%tail
is equivalent to:from pyensae.file_helper import file_tail file_tail(<filename>, <n>, <encoding>)
- static tail_parser()¶
defines the way to parse the magic command
%tail
- pyensae.filehelper.magic_file.register_file_magics(ip=None)¶
register magics function, can be called from a notebook
- Parameters:
ip – from
get_ipython()