[IPython-user] Evaluation of arbitrary expressions in the prompt string

Michael Scarpa M.Scarpa at uva.nl
Wed Sep 14 06:13:37 CDT 2005


Dear IPython users,

I just found out that this behavior disappeared when using the most 
recent version of IPython. Sorry for the fuzz. Still, I would like to 
know if doing this using the prompt string is the best way, or if there 
is a more feasible way to achieve what I need.

Kind regards,

Michael Scarpa


On Sep 14, 2005, at 12:32, Michael Scarpa wrote:

> 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
>
> _______________________________________________
> IPython-user mailing list
> IPython-user at scipy.net
> http://scipy.net/mailman/listinfo/ipython-user




More information about the IPython-user mailing list