为什么 readline.read_history_file 给我 'IOError: [Errno 2] No such file or directory' [英] Why does readline.read_history_file give me 'IOError: [Errno 2] No such file or directory'

查看:86
本文介绍了为什么 readline.read_history_file 给我 'IOError: [Errno 2] No such file or directory'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Python 历史文件位于 ~/.pyhistory 并包含以下内容:

from project.stuff import *放弃()从 project.stuff 导入 *my_thing = Thing.objects.get(id=21025)我的东西my_thing.child_set.all()my_thing.current_statemy_thing.summary_setmy_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' ) ]放弃()

我正在使用 virtualenv 和 virtualenvwrapper 来构建虚拟环境.今天我遇到了 readline 无法在我的历史文件中读取的问题:

<预><代码>>>>历史路径'/Users/johndoe/.pyhistory'>>>readline.read_history_file(historyPath)回溯(最近一次调用最后一次):文件<stdin>",第 1 行,位于 <module>IOError: [Errno 2] 没有那个文件或目录

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

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

什么可能导致这个问题?

解决方案

您的历史文件似乎是旧版本.尝试将其转换为后续版本的 readline 所期望的格式,最值得注意的是第一行应该是字面上的 '_HiStOrY_V2_' 并且所有空格都应替换为 '\040':

_HiStOrY_V2_从\040project.stuff\040import\040*放弃()从\040project.stuff\040import\040*my_thing\040=\040Thing.objects.get(id=21025)我的东西my_thing.child_set.all()my_thing.current_statemy_thing.summary_setmy_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]放弃()

我不确定这是底层 readline/libedit 库还是 Python readline 模块的怪癖,但这对我有用.

My Python history file exists at ~/.pyhistory and contains the following:

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()

I'm using virtualenv and virtualenvwrapper to build virtual environments. Today I'm having a problem with readline not reading in my history file:

>>> 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

The file is readable and writable by me:

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

What could cause this problem?

解决方案

Your history file appears to be an older version. Try converting it to the format expected by later versions of readline, most notably the first line should be literally '_HiStOrY_V2_' and all spaces should be replaced with '\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()

I am not sure whether this is a quirk of the underlying readline/libedit library or the Python readline module, but this is what worked for me.

这篇关于为什么 readline.read_history_file 给我 'IOError: [Errno 2] No such file or directory'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆