[IPython-user] Evaluation of arbitrary expressions in the prompt string
Michael Scarpa
M.Scarpa at uva.nl
Wed Sep 14 05:32:34 CDT 2005
Dear IPython users,
I have stumbled across the following problem: I would like to have
IPython execute a given command (calling the method of a defined
object) after every time I enter a new command at the prompt. I found
the description of IPython's arbitrary expression execution in the
prompt string in the online manual and thought this could do exactly
what I need. Since the object is defined when I start IPython (in a
python file loaded via "execfile" directive in the ipythonrc file), and
I want the method of this object to be called after each command I
issue, I thought that inserting something like "${object.method()}" in
my input prompt string would do. Alas, I keep getting a NameException,
claiming that the object is not defined. I made a test and replaced the
above expression with "${globals().keys()}", and indeed, that object I
try to call is not there. Even worse: nothing that is in my current
namespace (e.g. all the objects instantiated in the file I load via
"execfile" in my ipythonrc) is there!
In what namespace is the expression in the prompt string executed? And
how can I insert objects into it, or better, merge it with the current
namespace?
Alternatively: Is there a better way to do what I am trying to do?
Thanks a lot in advance for any reaction.
Kind regards,
Michael Scarpa
More information about the IPython-user
mailing list