当前位置: 首页>>代码示例>>Python>>正文


Python magic_arguments.parse_argstring方法代码示例

本文整理汇总了Python中IPython.core.magic_arguments.parse_argstring方法的典型用法代码示例。如果您正苦于以下问题:Python magic_arguments.parse_argstring方法的具体用法?Python magic_arguments.parse_argstring怎么用?Python magic_arguments.parse_argstring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IPython.core.magic_arguments的用法示例。


在下文中一共展示了magic_arguments.parse_argstring方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: watch

# 需要导入模块: from IPython.core import magic_arguments [as 别名]
# 或者: from IPython.core.magic_arguments import parse_argstring [as 别名]
def watch(self, line):
        """Watch memory for changes, shows the results in an ASCII data table.

        To use the results programmatically, see the watch_scanner() and
        watch_tabulator() functions.

        Keeps running until you kill it with a KeyboardInterrupt.
        """
        args = parse_argstring(self.watch, line)
        d = self.shell.user_ns['d']
        changes = watch_scanner(d, args.address)
        try:
            for line in watch_tabulator(changes):
                sys.stdout.write(line + '\n')
        except KeyboardInterrupt:
            pass 
开发者ID:scanlime,项目名称:coastermelt,代码行数:18,代码来源:shell_magics.py

示例2: ivt

# 需要导入模块: from IPython.core import magic_arguments [as 别名]
# 或者: from IPython.core.magic_arguments import parse_argstring [as 别名]
def ivt(self, line):
        """Read or modify the Interrupt Vector Table"""
        args = parse_argstring(self.ivt, line)
        d = self.shell.user_ns['d']

        if args.vector is None:
            # Show vector table. This only shows vectors with jumps, not
            # vectors that go directly to code.
            for addr in range(0, args.limit, 4):
                value = ivt_get(d, addr)
                if value is not None:
                    sys.stdout.write("vector %08x = %08x\n" % (addr, value))

        elif args.new_address is None:
            return ivt_get(d, args.vector)

        else:
            ivt_set(d, args.vector, args.new_address) 
开发者ID:scanlime,项目名称:coastermelt,代码行数:20,代码来源:shell_magics.py

示例3: sc_read

# 需要导入模块: from IPython.core import magic_arguments [as 别名]
# 或者: from IPython.core.magic_arguments import parse_argstring [as 别名]
def sc_read(self, line, cell=''):
        """Read blocks from the SCSI device.

        You can specify the LBA and address. With no arguments, goes into
        record-player mode and starts reading in order from the beginning.
        This is good if you just want the drive to read anything for testing.
        """
        args = parse_argstring(self.sc_read, line)
        d = self.shell.user_ns['d']
        lba = args.lba or 0

        while True:
            data = scsi_read(d, lba, args.blockcount or 1)
            if args.f:
                args.f.write(data)
                args.f.flush()

            sys.stdout.write(hexdump(data, address=lba*2048))
            if args.lba is None:
                # sequential mode
                lba += 1
            else:
                # Just one read
                break 
开发者ID:scanlime,项目名称:coastermelt,代码行数:26,代码来源:shell_magics.py

示例4: autonotify

# 需要导入模块: from IPython.core import magic_arguments [as 别名]
# 或者: from IPython.core.magic_arguments import parse_argstring [as 别名]
def autonotify(self, line):
        # Record options
        args = parse_argstring(self.autonotify, line)
        self.options["body"] = args.message.lstrip("\'\"").rstrip("\'\"")
        self.options['autonotify_after'] = args.after
        self.options['autonotify_output'] = args.output

        ### Register events
        ip = get_ipython()

        # Remove events if they're already registered
        # This is necessary because jupyter makes a new instance everytime
        pre, post = self.__class__._events
        if pre and pre in ip.events.callbacks['pre_run_cell']:
            ip.events.callbacks['pre_run_cell'].remove(pre)
        if post and post in ip.events.callbacks['post_run_cell']:
            ip.events.callbacks['post_run_cell'].remove(post)

        # Register new events
        ip.events.register('pre_run_cell', self.pre_run_cell)
        ip.events.register('post_run_cell', self.post_run_cell)
        self.__class__._events = self.pre_run_cell, self.post_run_cell 
开发者ID:ShopRunner,项目名称:jupyter-notify,代码行数:24,代码来源:jupyternotify.py

示例5: heat

# 需要导入模块: from IPython.core import magic_arguments [as 别名]
# 或者: from IPython.core.magic_arguments import parse_argstring [as 别名]
def heat(self, line, cell):
        """Method to profile the python code in the ipython cell and display it
        as a heatmap using py-heat package.

        :param line: Line value for the ipython line this magic is called from.
        :param cell: Cell value for the ipython cell this magic is called from.
        """
        args = magic_arguments.parse_argstring(self.heat, line)
        filename = args.out
        if filename is not None:
            filename = os.path.expanduser(args.out)

        _, tmp_file = mkstemp()
        with open(tmp_file, "wb") as f:
            f.write(cell.encode())

        pyheat = PyHeat(tmp_file)
        pyheat.create_heatmap()
        pyheat.show_heatmap(output_file=filename)
        pyheat.close_heatmap()

        os.remove(tmp_file) 
开发者ID:csurfer,项目名称:pyheatmagic,代码行数:24,代码来源:heat.py

示例6: b64

# 需要导入模块: from IPython.core import magic_arguments [as 别名]
# 或者: from IPython.core.magic_arguments import parse_argstring [as 别名]
def b64(self, line: str = "", cell: str = None) -> str:
        """
        Base64 IPython magic extension.

        Parameters
        ----------
        line : str, optional
            Line contents, by default ""
        cell : str, optional
            Cell contents, by default None

        Returns
        -------
        str
            Decoded text

        """
        if cell is None:
            results, df_results = base64.unpack(line)

        else:
            results, df_results = base64.unpack(cell)
        args = magic_arguments.parse_argstring(self.b64, line)

        if args.clean:
            results = re.sub(self._STRIP_TAGS, "", results)
        elif args.pretty:
            if _BS_AVAILABLE:
                xml_str = f"<decoded_string>{results}</decoded_string>"
                b_soup = BeautifulSoup(xml_str, "xml")
                results = b_soup.prettify()
        if args.out is not None:
            self.shell.user_ns[args.out] = (results, df_results)
        return results 
开发者ID:microsoft,项目名称:msticpy,代码行数:36,代码来源:sectools_magics.py

示例7: ioc

# 需要导入模块: from IPython.core import magic_arguments [as 别名]
# 或者: from IPython.core.magic_arguments import parse_argstring [as 别名]
def ioc(self, line="", cell=None) -> List[Tuple[str, List[str]]]:
        """
        Ioc Extract IPython magic extension.

        Parameters
        ----------
        line : str, optional
            Line contents, by default ""
        cell : str, optional
            Cell contents, by default None

        Returns
        -------
        List[Tuple[str, List[str]]]
            List of tuples of IoCs found grouped by type.

        """
        args = magic_arguments.parse_argstring(self.ioc, line)
        ioc_types = None
        if args.ioc_types:
            ioc_types = [ioc_type.strip() for ioc_type in args.ioc_types.split(",")]

        if cell is None:
            results = self._ioc_extract.extract(src=line, ioc_types=ioc_types)
        else:
            results = self._ioc_extract.extract(src=cell, ioc_types=ioc_types)
        iocs = [(ioc_type, list(ioc_res)) for ioc_type, ioc_res in results.items()]

        if args.out is not None:
            self.shell.user_ns[args.out] = results
        return iocs 
开发者ID:microsoft,项目名称:msticpy,代码行数:33,代码来源:sectools_magics.py

示例8: pxconfig

# 需要导入模块: from IPython.core import magic_arguments [as 别名]
# 或者: from IPython.core.magic_arguments import parse_argstring [as 别名]
def pxconfig(self, line):
        """configure default targets/blocking for %px magics"""
        args = magic_arguments.parse_argstring(self.pxconfig, line)
        if args.targets:
            self.view.targets = self._eval_target_str(args.targets)
        if args.block is not None:
            self.view.block = args.block
        if args.set_verbose is not None:
            self.verbose = args.set_verbose 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:11,代码来源:magics.py

示例9: result

# 需要导入模块: from IPython.core import magic_arguments [as 别名]
# 或者: from IPython.core.magic_arguments import parse_argstring [as 别名]
def result(self, line=''):
        """Print the result of the last asynchronous %px command.
        
        This lets you recall the results of %px computations after
        asynchronous submission (block=False).

        Examples
        --------
        ::

            In [23]: %px os.getpid()
            Async parallel execution on engine(s): all

            In [24]: %pxresult
            Out[8:10]: 60920
            Out[9:10]: 60921
            Out[10:10]: 60922
            Out[11:10]: 60923
        """
        args = magic_arguments.parse_argstring(self.result, line)
        
        if self.last_result is None:
            raise UsageError(NO_LAST_RESULT)
        
        self.last_result.get()
        self.last_result.display_outputs(groupby=args.groupby) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:28,代码来源:magics.py

示例10: debug

# 需要导入模块: from IPython.core import magic_arguments [as 别名]
# 或者: from IPython.core.magic_arguments import parse_argstring [as 别名]
def debug(self, line='', cell=None):
        """Activate the interactive debugger.

        This magic command support two ways of activating debugger.
        One is to activate debugger before executing code.  This way, you
        can set a break point, to step through the code from the point.
        You can use this mode by giving statements to execute and optionally
        a breakpoint.

        The other one is to activate debugger in post-mortem mode.  You can
        activate this mode simply running %debug without any argument.
        If an exception has just occurred, this lets you inspect its stack
        frames interactively.  Note that this will always work only on the last
        traceback that occurred, so you must call this quickly after an
        exception that you wish to inspect has fired, because if another one
        occurs, it clobbers the previous one.

        If you want IPython to automatically do this on every exception, see
        the %pdb magic for more details.
        """
        args = magic_arguments.parse_argstring(self.debug, line)

        if not (args.breakpoint or args.statement or cell):
            self._debug_post_mortem()
        else:
            code = "\n".join(args.statement)
            if cell:
                code += "\n" + cell
            self._debug_exec(code, args.breakpoint) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:31,代码来源:execution.py

示例11: capture

# 需要导入模块: from IPython.core import magic_arguments [as 别名]
# 或者: from IPython.core.magic_arguments import parse_argstring [as 别名]
def capture(self, line, cell):
        """run the cell, capturing stdout/err"""
        args = magic_arguments.parse_argstring(self.capture, line)
        out = not args.no_stdout
        err = not args.no_stderr
        with capture_output(out, err) as io:
            self.shell.run_cell(cell)
        if args.output:
            self.shell.user_ns[args.output] = io 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:11,代码来源:execution.py

示例12: matplotlib

# 需要导入模块: from IPython.core import magic_arguments [as 别名]
# 或者: from IPython.core.magic_arguments import parse_argstring [as 别名]
def matplotlib(self, line=''):
        """Set up matplotlib to work interactively.
        
        This function lets you activate matplotlib interactive support
        at any point during an IPython session.
        It does not import anything into the interactive namespace.
        
        If you are using the inline matplotlib backend for embedded figures,
        you can adjust its behavior via the %config magic::

            # enable SVG figures, necessary for SVG+XHTML export in the qtconsole
            In [1]: %config InlineBackend.figure_format = 'svg'

            # change the behavior of closing all figures at the end of each
            # execution (cell), or allowing reuse of active figures across
            # cells:
            In [2]: %config InlineBackend.close_figures = False

        Examples
        --------
        In this case, where the MPL default is TkAgg::

            In [2]: %matplotlib
            Using matplotlib backend: TkAgg

        But you can explicitly request a different backend::

            In [3]: %matplotlib qt
        """
        args = magic_arguments.parse_argstring(self.matplotlib, line)
        gui, backend = self.shell.enable_matplotlib(args.gui)
        self._show_matplotlib_backend(args.gui, backend) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:34,代码来源:pylab.py

示例13: notebook

# 需要导入模块: from IPython.core import magic_arguments [as 别名]
# 或者: from IPython.core.magic_arguments import parse_argstring [as 别名]
def notebook(self, s):
        """Export and convert IPython notebooks.

        This function can export the current IPython history to a notebook file
        or can convert an existing notebook file into a different format. For
        example, to export the history to "foo.ipynb" do "%notebook -e foo.ipynb".
        To export the history to "foo.py" do "%notebook -e foo.py". To convert
        "foo.ipynb" to "foo.json" do "%notebook -f json foo.ipynb". Possible
        formats include (json/ipynb, py).
        """
        args = magic_arguments.parse_argstring(self.notebook, s)

        from IPython.nbformat import current
        args.filename = unquote_filename(args.filename)
        if args.export:
            fname, name, format = current.parse_filename(args.filename)
            cells = []
            hist = list(self.shell.history_manager.get_range())
            for session, prompt_number, input in hist[:-1]:
                cells.append(current.new_code_cell(prompt_number=prompt_number,
                                                   input=input))
            worksheet = current.new_worksheet(cells=cells)
            nb = current.new_notebook(name=name,worksheets=[worksheet])
            with io.open(fname, 'w', encoding='utf-8') as f:
                current.write(nb, f, format);
        elif args.format is not None:
            old_fname, old_name, old_format = current.parse_filename(args.filename)
            new_format = args.format
            if new_format == u'xml':
                raise ValueError('Notebooks cannot be written as xml.')
            elif new_format == u'ipynb' or new_format == u'json':
                new_fname = old_name + u'.ipynb'
                new_format = u'json'
            elif new_format == u'py':
                new_fname = old_name + u'.py'
            else:
                raise ValueError('Invalid notebook format: %s' % new_format)
            with io.open(old_fname, 'r', encoding='utf-8') as f:
                nb = current.read(f, old_format)
            with io.open(new_fname, 'w', encoding='utf-8') as f:
                current.write(nb, f, new_format) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:43,代码来源:basic.py

示例14: jsmva

# 需要导入模块: from IPython.core import magic_arguments [as 别名]
# 或者: from IPython.core.magic_arguments import parse_argstring [as 别名]
def jsmva(self, line):
        from JsMVA.JPyInterface import functions
        args = parse_argstring(self.jsmva, line)
        if args.arg == 'on':
           functions.register()
        elif args.arg == 'off':
           functions.unregister()
        elif args.arg == "noOutput":
           functions.register(True)   


## Function for registering the magic class 
开发者ID:dnanexus,项目名称:parliament2,代码行数:14,代码来源:JsMVAMagic.py

示例15: vegalite

# 需要导入模块: from IPython.core import magic_arguments [as 别名]
# 或者: from IPython.core.magic_arguments import parse_argstring [as 别名]
def vegalite(line, cell):
    """Cell magic for displaying vega-lite visualizations in CoLab.

    %%vegalite [dataframe] [--json] [--version=3]

    Visualize the contents of the cell using Vega-Lite, optionally
    specifying a pandas DataFrame object to be used as the dataset.

    if --json is passed, then input is parsed as json rather than yaml.
    """
    args = magic_arguments.parse_argstring(vegalite, line)
    version = args.version
    assert version in RENDERERS["vega-lite"]
    VegaLite = RENDERERS["vega-lite"][version]
    data_transformers = TRANSFORMERS["vega-lite"][version]

    if args.json:
        spec = json.loads(cell)
    elif not YAML_AVAILABLE:
        try:
            spec = json.loads(cell)
        except json.JSONDecodeError:
            raise ValueError(
                "%%vegalite: spec is not valid JSON. "
                "Install pyyaml to parse spec as yaml"
            )
    else:
        spec = yaml.load(cell, Loader=yaml.FullLoader)

    if args.data is not None:
        data = _get_variable(args.data)
        spec["data"] = _prepare_data(data, data_transformers)

    return VegaLite(spec) 
开发者ID:altair-viz,项目名称:altair,代码行数:36,代码来源:_magics.py


注:本文中的IPython.core.magic_arguments.parse_argstring方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。