本文整理汇总了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())
示例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()
示例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)
示例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)
示例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)
示例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()
示例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()
示例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)
示例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)
示例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
示例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
示例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()
示例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()
示例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)
示例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)