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

标签 windows-vista prompt ipython

有没有办法在我的 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/Scripts]
    |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'[\#] '

最佳答案

最简单的方法是编辑您的 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 [\#]: '

关于windows-vista - 有没有办法在我的 IPython 提示中获取本地时间戳?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3879752/

相关文章:

java - 在 Windows Vista 上请求 Java 应用程序的管理员权限

javascript - 当用户取消时显示提示,它会被捕获 typeError

在页面显示之前加载 Javascript 提示

python - 在 ipython 控制台中调试魔术功能

windows-vista - OpenInputDesktop() 确定安全/登录桌面

flash - 如何以编程方式防止 Vista(和 Windows 7)中的 "Program Compatibility Assistant"出现?

javascript - 一个简单的 JS+HTML 脚本不适合我

python - spyder IDE 的 ipython 启动配置

python - 更改 Pandas 中的默认选项

windows-vista - 哪个Vista版本最适合开发人员计算机?