为什么readline.read_history_文件给我'IOError:[Errno 2]没有这样的文件或目录'

2024-09-28 01:25:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我的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没有读取我的历史文件:

^{pr2}$

文件对我来说是可读写的:

[johndoe@here]# ls -l ~/.pyhistory
-rw-------  1 johndoe  somegroup  325 21 Sep  2012 /Users/johndoe/.pyhistory

什么会导致这个问题?在


Tags: 文件fromimportprojectchildmy历史all
1条回答
网友
1楼 · 发布于 2024-09-28 01:25:21

您的历史记录文件似乎是旧版本。尝试将其转换为readline的后续版本所期望的格式,最明显的是第一行应该是字面上的''u 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模块的一个怪癖,但这正是我的工作方式。

相关问题 更多 >

    热门问题