python history文件_为什么Python的read_history_文件不允许我进行操作?

所以。我拥有名为~/.osc_history的文件,如下所示:$ w

17:53 up 3:15, 5 users, load averages: 1.30 1.17 1.10

USER TTY FROM LOGIN@ IDLE WHAT

kyma console - 14:39 3:14 -

kyma s001 - 17:20 - w

$ ls -l ~/.osc_history

-rw-r--r-- 1 kyma staff 13 Mar 6 17:41 /Users/kyma/.osc_history

$ ls -lO ~/.osc_history

-rw-r--r-- 1 kyma staff - 13 Mar 6 17:41 /Users/kyma/.osc_history

文件中的标头正确:

^{pr2}$

在交互式提示符下,以下代码运行良好:$ python

Python 2.7.10 (default, Jul 30 2016, 19:40:32)

[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>> import os.path

>>> import readline

>>> histfile = os.path.join(os.path.expanduser("~"), ".osc_history")

>>> histfile

'/Users/kyma/.osc_history'

>>> readline.read_history_file(histfile)

>>> ^D

但是,当我试图运行以下程序时,我称之为“yeuch.py公司"... 在#!/usr/bin/env python

# -*- coding: utf-8 -*-

import readline # Command line history

import os.path

histfile = os.path.join(os.path.expanduser("~"), ".osc_history")

if not os.path.isfile(histfile): # If there's no history file...

empty = open(histfile, "a") # ... create an ALMOST empty one...

empty.write("_HiStOrY_V2_\n") # ... with the special header line

empty.close()

readline.read_history_file(histfile) # Read history from previous sessions

readline.set_history_length(1000) # Default length was -1 (infinite)

……我明白了:$ python yeuch.py

Traceback (most recent call last):

File "yeuch.py", line 14, in

readline.read_history_file(histfile) # Read history from previous sessions

IOError: [Errno 1] Operation not permitted

怎么回事?(我希望我没有多次忽略一些愚蠢的打字错误…)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值