當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。