views:

27

answers:

3

64-bit Vista Python 2.6 IPython 0.10

Is there a way to get a local timestamp in my IPython prompt.

My current default prompt is

[C:Python26/Scripts] |9>

+1  A: 

The easiest way is to edit your ipythonrc (in your home\_ipython directory), and add these lines:

import_mod datetime
prompt_in1 '${datetime.datetime.now()} In [\#]: '
# or
prompt_in1 '${datetime.datetime.now().strftime("%H:%M:%S")} In [\#]: '

Alternatively, you can also just add the import_mod datetime to the rc file, and add this to the main() function of ipy_user_conf.py (in the same directory):

o = ip.options
o.prompt_in1 = r'${datetime.datetime.now()} In [\#]: '
# or
o.prompt_in1 = r'${datetime.datetime.now().strftime("%H:%M:%S")} In [\#]: '
ma3
import_all("os sys random datetime") #execf('~/_ipython/ns.py') # -- prompt # A different, more compact set of prompts from the default ones, that # always show your current location in the filesystem: o.prompt_in1 = r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Normal\n\C_Green|\#>' o.prompt_in2 = r'.\D: ' o.prompt_out = r'[\#] ' o.prompt_in1 = r'${datetime.now().strftime("%H:%M:%S")} In[\#]:'
NotSuper
+1  A: 

(This was too long for a comment)

OK, I tried to follow your directions exactly. However, my experience has been that all config editing is best kept to my ipy_user_conf.py . To quote from it:

""" User configuration file for IPython (ipy_user_conf.py)

This is a more flexible and safe way to configure ipython than *rc files (ipythonrc, ipythonrc-pysh etc.)

This file is always imported on ipython startup. You can import the ipython extensions you need here (see IPython/Extensions directory).

Feel free to edit this file to customize your ipython experience.

Note that as such this file does nothing, for backwards compatibility. Consult e.g. file 'ipy_profile_sh.py' for an example of the things you can do here.

See http://ipython.scipy.org/moin/IpythonExtensionApi for detailed description on what you could do here. """ So I now have these lines in main(): # -- prompt # A different, more compact set of prompts from the default ones, that # always show your current location in the filesystem:

o.prompt_in1 = r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Normal\n\C_Green|\#>'
o.prompt_in2 = r'.\D: '
o.prompt_out = r'[\#] '

And I get this, for an example:

16:49:50 In[9]:1/7 1 [9] 0.14285714285714285

16:50:09 In[10]:

Questions: 1. What is that '1'? 2. How can I keep the current directory in the prompt? Before, I had [C:Python26/Scripts] |8>

NotSuper
I left out this line that is also in ipy_user_conf.py: import_all("os sys random datetime")
NotSuper
Once more with feeling.I'm so sorry for the mess I've made. I need to report the lines I either added or modified are:import_all("os sys random datetime") o.prompt_in1 = r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Normal\n\C_Green|\#>'
NotSuper
A: 

Once more with feeling. I'm so sorry for the mess I've made. I need to report the lines I either added or modified actually are:

import_all("os sys random datetime")
o.prompt_in1 = r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Normal\n\C_Green|\#>'
o.prompt_in1 = r'${datetime.now().strftime("%H:%M:%S")}[\#]:'
o.prompt_out = r'[\#] '
NotSuper