[IPython-dev] IPython prompt delay
Fernando Perez
Fernando.Perez at colorado.edu
Thu Dec 1 12:01:05 EST 2005
Frédéric Mantegazza wrote:
> Le Mercredi 30 Novembre 2005 19:05, Fernando Perez a écrit :
>
>
>>>It works, but it displays 'None' before PyMAD. It is because
>>>time.sleep() returns None, I presume. How can I make it return an empty
>>>string, instead ?
>>
>>Wrap it:
>>
>>def mysleep(t):
>> time.sleep(t)
>> return ''
>
>
> I tied that, but IPython can't find my function. Where do I have to put it
> to be reachable by the prompt at runtime?
The prompt system executes in the global environment of the user. The
simplest way to define extra things is to put them in a pure python file and
call that from your ipythonrc. This should clarify it:
planck[~/.ipython]> cat ipythonrc-myprompt
prompt_in1 '${prompt1()} \nIn [\#]: '
execfile myprompt.py
planck[~/.ipython]> cat myprompt.py
def prompt1():
return '<Hi Fred>'
planck[~/.ipython]> ipython -p myprompt
Python 2.3.4 (#1, Feb 2 2005, 12:11:53)
Type "copyright", "credits" or "license" for more information.
IPython 0.6.16.svn -- An enhanced Interactive Python.
? -> Introduction to IPython's features.
%magic -> Information about IPython's 'magic' % functions.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.
IPython profile: myprompt
<Hi Fred>
In [1]:
Do you really want to exit ([y]/n)?
planck[~/.ipython]>
> I found another solution :
>
> str(time.sleep(0.1))[1:0]
That will do too.
Cheers,
f
More information about the IPython-dev
mailing list