有没有办法在我的 IPython 提示符中获取本地时间戳?

发布于 2024-09-26 22:31:22 字数 1782 浏览 5 评论 0原文

有没有办法在我的 IPython 提示符中获取本地时间戳?我在 64 位 Windows Vista 上使用 IPython 0.10 和 Python 2.6。

我当前的默认提示是

[C:Python26/Scripts]
|9>

好的,我尝试完全按照您的指示进行操作。但是,我的经验是,所有配置编辑最好保留在我的 ipy_user_conf.py 中。引用它:

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.

所以我现在在 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'[\#] '

我得到了这个,例如:

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

16:50:09 In[10]:

问题:

  1. 1 是什么?
  2. 如何在提示符中保留当前目录?之前,我有过

    <前><代码>[C:Python26/脚本] |8>

一次感触。 我对我造成的混乱感到非常抱歉。我需要报告我添加或修改的行实际上是:

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'[\#] '

Is there a way to get a local timestamp in my IPython prompt? I'm using IPython 0.10 and Python 2.6 on 64-bit Windows Vista.

My current default prompt is

[C:Python26/Scripts]
|9>

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>
    

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'[\#] '

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人生戏 2024-10-03 22:31:22

最简单的方法是编辑 ipythonrc (在您的 home\_ipython 目录中),并添加以下行:

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

或者,您也可以将 import_mod datetime 添加到 rc 文件,并将其添加到 ipy_user_conf.py 的 main() 函数中(在同一目录中):

o = ip.options
o.prompt_in1 = r'${datetime.datetime.now()} In [\#]: '
# or
o.prompt_in1 = r'${datetime.datetime.now().strftime("%H:%M:%S")} In [\#]: '

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 [\#]: '
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文