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


Python code.interact方法代码示例

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


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

示例1: anyblok_interpreter

# 需要导入模块: import code [as 别名]
# 或者: from code import interact [as 别名]
def anyblok_interpreter():
    """Execute a script or open an interpreter
    """
    registry = anyblok.start('interpreter')
    if registry:
        registry.commit()
        python_script = Configuration.get('python_script')
        if python_script:
            with open(python_script, "r") as fh:
                exec(fh.read(), None, locals())
        else:
            try:
                from IPython import embed
                embed()
            except ImportError:
                import code
                code.interact(local=locals()) 
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:19,代码来源:scripts.py

示例2: main

# 需要导入模块: import code [as 别名]
# 或者: from code import interact [as 别名]
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--package', action='append')
    parser.add_argument('--dir', action='append')
    parser.add_argument('-m', action='store', metavar='MODULE')
    args, rest = parser.parse_known_args()
    if args.package:
        PACKAGES.extend(args.package)
    if args.dir:
        DIRS.extend(os.path.abspath(d) for d in args.dir)
    if not PACKAGES and not DIRS:
        DIRS.append(os.getcwd())
    if args.m:
        sys.argv[1:] = rest
        runpy.run_module(args.m, run_name='__main__', alter_sys=True)
    elif rest:
        sys.argv = rest
        converted = maybe_2to3(rest[0])
        with open(converted) as f:
            new_globals = dict(__name__='__main__',
                               __file__=rest[0])
            exec(f.read(), new_globals)
    else:
        import code
        code.interact() 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:27,代码来源:auto2to3.py

示例3: test_basic_functions

# 需要导入模块: import code [as 别名]
# 或者: from code import interact [as 别名]
def test_basic_functions(self):
        import code
        import doctest
        import sys

        db = pg_simple.PgSimple(self.pool)
        if sys.argv.count('--interact'):
            db.log = sys.stdout
            code.interact(local=locals())
        else:
            try:
                # Setup tables
                self._drop_tables(db)
                self._create_tables(db, fill=True)
                # Run tests
                doctest.testmod(optionflags=doctest.ELLIPSIS)
            finally:
                # Drop tables
                self._drop_tables(db)
        self.assertEqual(True, True) 
开发者ID:masroore,项目名称:pg_simple,代码行数:22,代码来源:main.py

示例4: test_connection_auto_commit

# 需要导入模块: import code [as 别名]
# 或者: from code import interact [as 别名]
def test_connection_auto_commit(self):
        import code
        import sys

        with pg_simple.PgSimple(self.pool) as db:
            if sys.argv.count('--interact'):
                db.log = sys.stdout
                code.interact(local=locals())
            else:
                self._drop_tables(db)
                self._create_tables(db, fill=True)

        with pg_simple.PgSimple(self.pool) as db:
            try:
                self._check_table(db, 'pg_t1')
            finally:
                self._drop_tables(db) 
开发者ID:masroore,项目名称:pg_simple,代码行数:19,代码来源:main.py

示例5: NativePythonSupport

# 需要导入模块: import code [as 别名]
# 或者: from code import interact [as 别名]
def NativePythonSupport(user_session):
    """Launch the rekall session using the native python interpreter.

    Returns:
      False if we failed to use IPython. True if the session was run and exited.
    """
    # If the ipython shell is not available, we can use the native python shell.
    import code

    # Try to enable tab completion
    try:
        import rlcompleter, readline  # pylint: disable=unused-variable
        readline.parse_and_bind("tab: complete")
    except ImportError:
        pass

    # Prepare the session for running within the native python interpreter.
    user_session.PrepareLocalNamespace()
    code.interact(banner=constants.BANNER, local=user_session.locals) 
开发者ID:google,项目名称:rekall,代码行数:21,代码来源:ipython.py

示例6: main

# 需要导入模块: import code [as 别名]
# 或者: from code import interact [as 别名]
def main():
    # getting the customized configurations from the command-line arguments.
    args = KGEArgParser().get_args(sys.argv[1:])

    # Preparing data and cache the data for later usage
    knowledge_graph = KnowledgeGraph(dataset=args.dataset_name, custom_dataset_path=args.dataset_path)
    knowledge_graph.prepare_data()

    # Extracting the corresponding model config and definition from Importer().
    config_def, model_def = Importer().import_model_config(args.model_name.lower())
    config = config_def(args)
    model = model_def(config)

    # Create, Compile and Train the model. While training, several evaluation will be performed.
    trainer = Trainer(model, config)
    trainer.build_model()
    trainer.train_model()
    
    #can perform all the inference here after training the model
    trainer.enter_interactive_mode()
    
    code.interact(local=locals())

    trainer.exit_interactive_mode() 
开发者ID:Sujit-O,项目名称:pykg2vec,代码行数:26,代码来源:inference.py

示例7: start_console

# 需要导入模块: import code [as 别名]
# 或者: from code import interact [as 别名]
def start_console(self):
        # Set up initial console environment
        console_env = {
            'ad': self._ad,
            'pprint': pprint.pprint,
        }

        # Start the services
        self._start_services(console_env)

        # Start the console
        console_banner = self._get_banner(self._ad.serial)
        code.interact(banner=console_banner, local=console_env)

        # Tear everything down
        self._ad.services.stop_all() 
开发者ID:google,项目名称:mobly,代码行数:18,代码来源:jsonrpc_shell_base.py

示例8: do_python

# 需要导入模块: import code [as 别名]
# 或者: from code import interact [as 别名]
def do_python(self, line):
        """
        Start an interactive python interpreter. The namespace of the
        interpreter is updated with expression nicities.  You may also
        specify a line of python code as an argument to be exec'd without
        beginning an interactive python interpreter on the controlling
        terminal.

        Usage: python [pycode]
        """
        locals = self.getExpressionLocals()
        if len(line) != 0:
            cobj = compile(line, 'cli_input', 'exec')
            exec(cobj, locals)
        else:
            code.interact(local=locals) 
开发者ID:joxeankoret,项目名称:nightmare,代码行数:18,代码来源:cli.py

示例9: interact

# 需要导入模块: import code [as 别名]
# 或者: from code import interact [as 别名]
def interact(pid=0,server=None,trace=None):

    """
    Just a cute and dirty way to get a tracer attached to a pid
    and get a python interpreter instance out of it.
    """

    global remote
    remote = server

    if trace == None:
        trace = getTrace()
        if pid:
            trace.attach(pid)

    mylocals = {}
    mylocals["trace"] = trace

    code.interact(local=mylocals) 
开发者ID:joxeankoret,项目名称:nightmare,代码行数:21,代码来源:__init__.py

示例10: _spawn_python_shell

# 需要导入模块: import code [as 别名]
# 或者: from code import interact [as 别名]
def _spawn_python_shell(self, arg):
        import winappdbg
        banner = ('Python %s on %s\nType "help", "copyright", '
                 '"credits" or "license" for more information.\n')
        platform = winappdbg.version.lower()
        platform = 'WinAppDbg %s' % platform
        banner = banner % (sys.version, platform)
        local = {}
        local.update(__builtins__)
        local.update({
            '__name__'  : '__console__',
            '__doc__'   : None,
            'exit'      : self._python_exit,
            'self'      : self,
            'arg'       : arg,
            'winappdbg' : winappdbg,
        })
        try:
            code.interact(banner=banner, local=local)
        except SystemExit:
            # We need to catch it so it doesn't kill our program.
            pass 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:24,代码来源:interactive.py

示例11: do_python

# 需要导入模块: import code [as 别名]
# 或者: from code import interact [as 别名]
def do_python(self,arg):
		""" start the local python interpreter (for debugging purposes) """
		orig_exit=builtins.exit
		orig_quit=builtins.quit
		def disabled_exit(*args, **kwargs):
			self.display_warning("exit() disabled ! use ctrl+D to exit the python shell")
		builtins.exit=disabled_exit
		builtins.quit=disabled_exit
		oldcompleter=readline.get_completer()
		try:
			local_ns={"pupsrv":self.pupsrv}
			readline.set_completer(PythonCompleter(local_ns=local_ns).complete)
			readline.parse_and_bind('tab: complete')
			code.interact(local=local_ns)
		except Exception as e:
			self.display_error(str(e))
		finally:
			readline.set_completer(oldcompleter)
			readline.parse_and_bind('tab: complete')
			builtins.exit=orig_exit
			builtins.quit=orig_quit 
开发者ID:krintoxi,项目名称:NoobSec-Toolkit,代码行数:23,代码来源:PupyCmd.py

示例12: main

# 需要导入模块: import code [as 别名]
# 或者: from code import interact [as 别名]
def main():
	kb = Keyboard()
	
	if appex.is_widget():
		appex.set_widget_view(kb.root)
	else:
		kb.root.present("sheet")
	
	def read(self, size=-1):
		return kb.read(size)
	
	def readline(self):
		return kb.read()
	
	sys.stdin.__class__.read = read
	sys.stdin.__class__.readline = readline
	
	code.interact() 
开发者ID:dgelessus,项目名称:pythonista-scripts,代码行数:20,代码来源:today_python_console.py

示例13: shell

# 需要导入模块: import code [as 别名]
# 或者: from code import interact [as 别名]
def shell(self, stage):
        self.set_up_yolofile_context(stage=stage)
        self._yolo_file = self.yolo_file.render(**self.context)

        # Set up AWS credentials for the shell
        self._setup_aws_credentials_in_environment(
            self.context.account.account_number,
            self.context.stage.region,
        )

        # Select Python shell
        if have_bpython:
            bpython.embed()
        elif have_ipython:
            start_ipython(argv=[])
        else:
            code.interact() 
开发者ID:rackerlabs,项目名称:yolo,代码行数:19,代码来源:client.py

示例14: check_forever

# 需要导入模块: import code [as 别名]
# 或者: from code import interact [as 别名]
def check_forever(self, checkers):
        timeline.schedule_checks(checkers)
        logger.info("Starting infinite loop")
        while not self.signals['reload_conf_pending']:
            if self.signals['interrupted']:
                break
            if self.signals['open_backdoor']:
                self.signals['open_backdoor'] = False
                code.interact(
                    banner="Kibitzr debug shell",
                    local=locals(),
                )
            timeline.run_pending()
            if self.signals['interrupted']:
                break
            time.sleep(1) 
开发者ID:kibitzr,项目名称:kibitzr,代码行数:18,代码来源:app.py

示例15: shell

# 需要导入模块: import code [as 别名]
# 或者: from code import interact [as 别名]
def shell(runtime, script=None, python=None):
    # alias for backwards-compatibility
    variables = {
        "config": runtime,
        "runtime": runtime,
        "project_config": runtime.project_config,
    }

    if script:
        if python:
            raise click.UsageError("Cannot specify both --script and --python")
        runpy.run_path(script, init_globals=variables)
    elif python:
        exec(python, variables)
    else:
        code.interact(local=variables) 
开发者ID:SFDO-Tooling,项目名称:CumulusCI,代码行数:18,代码来源:cci.py


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