di approfondire la risposta di IVA: embedding-a-shell, incoporating code
e ipython.
def prompt(vars=None, message="welcome to the shell"):
#prompt_message = "Welcome! Useful: G is the graph, DB, C"
prompt_message = message
try:
from IPython.Shell import IPShellEmbed
ipshell = IPShellEmbed(argv=[''],banner=prompt_message,exit_msg="Goodbye")
return ipshell
except ImportError:
if vars is None: vars=globals()
import code
import rlcompleter
import readline
readline.parse_and_bind("tab: complete")
# calling this with globals ensures we can see the environment
print prompt_message
shell = code.InteractiveConsole(vars)
return shell.interact
p = prompt()
p()
fonte
2010-04-12 04:15:31
Grazie a tutti! Per la cronaca, il modo più semplice per utilizzare il modulo di codice per raggiungere questo obiettivo è la seguente: codice di importazione code.interact (locali = globali()) –
Per ottenere le variabili locali nello spazio dei nomi così, è necessario ' code.interact (local = dict (globals(), ** locals()) '. Nota l'aggiunta di' ** locals'. Mi stavo chiedendo questa domanda da solo, e il tuo commento è stato la risposta migliore che ho trovato: -) –