IVA के जवाब पर विस्तार से बता दें: embedding-a-shell, code
और IPython incoporating।
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()
स्रोत
2010-04-12 04:15:31
सभी को धन्यवाद! आयात कोड code.interact (स्थानीय = वैश्विक()) –
रूप में अच्छी तरह नेम स्पेस में स्थानीय चर पाने के लिए आपको जरूरत ': रिकॉर्ड के लिए, सबसे आसान तरीका है इस लक्ष्य को हासिल करने के लिए कोड मॉड्यूल का उपयोग करने के लिए निम्न है code.interact (स्थानीय = dict (globals(), ** स्थानीय()) ' ' ** स्थानीय लोगों 'के अतिरिक्त ध्यान दें। मैं इस सवाल को स्वयं सोच रहा था, और आपकी टिप्पणी मुझे मिली सबसे अच्छी प्रतिक्रिया थी: -) –