Reputation: 1450
I want to be able to push code into the IDLE shell history from a script such that
>>>somecode = """
def somefunc():
pass
"""
>>>idlelib.some_unknown_add_to_history_method(somecode)
>>><ALT-p>
Results in:
>>>def somefunc():
pass
So that I can edit and re-evaluate somefunc just as if I had manually pasted or entered the code into the shell. Is there an existing way to do this, or will I need to write an IDLE extension?
Upvotes: 0
Views: 117
Reputation: 961
IDLE does not offer a way to insert an item into its shell history. You could change the code in PyShell.py.
Take a look at the IdleX project for a lot of examples of IDLE extensions. There's an extension for providing persistent history across IDLE sessions which might be a good starting point for writing your own extension. See PersistentHistory.py from that project.
You might like its SubCode extension which allows you to edit and re-evaluate parts of your code directly from the editor by pressing Ctrl+Enter. You could also highlight code in the editor and run it by pressing F9.
Upvotes: 1