我的 Python 历史文件位于 ~/.pyhistory 并包含以下内容:
from project.stuff import *
quit()
from project.stuff import *
my_thing = Thing.objects.get(id=21025)
my_thing
my_thing.child_set.all()
my_thing.current_state
my_thing.summary_set
my_thing.summary_set.all()
[ x.type for x in my_thing.child_set.all() ]
[ x.type for x in my_thing.child_set.all().order_by( 'datesubmitted' ) ]
quit()
我正在使用 virtualenv 和 virtualenvwrapper 来构建虚拟环境。今天,我遇到了 readline 未读取历史文件的问题:
>>> historyPath
'/Users/johndoe/.pyhistory'
>>> readline.read_history_file(historyPath)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 2] No such file or directory
该文件对我来说是可读可写的:
[johndoe@here]# ls -l ~/.pyhistory
-rw------- 1 johndoe somegroup 325 21 Sep 2012 /Users/johndoe/.pyhistory
什么可能导致这个问题?
您的历史文件似乎是旧版本。尝试将其转换为更高版本的 readline 所需的格式,最值得注意的是第一行应字面意思是“_HiStOrY_V2_”,所有空格应替换为“\040”:
_HiStOrY_V2_
from\040project.stuff\040import\040*
quit()
from\040project.stuff\040import\040*
my_thing\040=\040Thing.objects.get(id=21025)
my_thing
my_thing.child_set.all()
my_thing.current_state
my_thing.summary_set
my_thing.summary_set.all()
[\040x.type\040for\040x\040in\040my_thing.child_set.all()\040]
[\040x.type\040for\040x\040in\040my_thing.child_set.all().order_by(\040'datesubmitted'\040)\040]
quit()
我不确定这是否是底层 readline/libedit 库或 Python readline 模块的怪癖,但这对我有用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)