python - 如何解决,PermissionError : [Errno 13] Permission denied: 'test.from'

标签 python pandas sqlite

我正在学习有关 Python 聊天机器人训练数据的教程。但是,每当我运行代码时,我都会收到此错误,

line 22, in <module>
    with open('test.from','a', encoding='utf8') as f:
PermissionError: [Errno 13] Permission denied: 'test.from'

我转到我的项目文件夹并更改了“员工”和“每个人”的权限。我这样做是为了让两者都能读和写。然而这没有任何作用,我仍然遇到同样的错误。

下面是我的代码,

import sqlite3
import pandas as pd

timeframes = ['2015-01']

for timeframe in timeframes:
    connection = sqlite3.connect('/Users/usr/Desktop/fileName/RC_{}.db'.format(timeframe))
    c = connection.cursor()
    limit = 5000
    last_unix = 0
    cur_length = limit
    counter = 0
    test_done = False

    while cur_length == limit:
        df = pd.read_sql("SELECT * FROM parent_reply WHERE unix > {} and parent NOT NULL and score > 0 ORDER BY unix ASC LIMIT {}".format(last_unix,limit),connection)
        last_unix = df.tail(1)['unix'].values[0]
        cur_length = len(df)

        if not test_done:
            with open('test.from','a', encoding='utf8') as f:
                for content in df['parent'].values:
                    f.write(content+'\n')
            with open('test.to','a', encoding='utf8') as f:
                for content in df['comment'].values:
                    f.write(str(content)+'\n')
            test_done = True

最佳答案

可能的原因

  1. 用户没有该目录的写入权限。

  2. 文件已被写保护。

  3. 该文件正在其他来源使用。

很可能您在该目录中没有写访问权限,因此请输入您有权访问的目录的完整路径,然后重试。

关于python - 如何解决,PermissionError : [Errno 13] Permission denied: 'test.from' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56386244/

相关文章:

python - 如何替换pandas中的数据框

python - Pandas 中带有时区列的时间戳

python - 使用 pd.xlsxwriter 根据该行中的单个单元格有条件地格式化整行

javascript - 如何在 html5 中使用现有的 sqlite 数据库

c - SQLite3 和限制结果的数量

python - 如何为 GPU 设备指定或设置变量

python - Python 上的循环导入

pandas - 如何在style.apply之后显示 Pandas 数据框的截断形式?

sql - 如何编写 SQLite 代码以显示指定代码及其来自 group_concat 函数的关联代码?

python - 尝试检查满足这些条件的字符串