首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何解决,PermissionError:[Errno 13]权限被拒绝:'test.from‘

如何解决,PermissionError:[Errno 13]权限被拒绝:'test.from‘
EN

Stack Overflow用户
提问于 2019-05-31 06:08:11
回答 1查看 4.4K关注 0票数 2

我正在学习一篇关于python聊天机器人训练数据的教程。然而,每当我运行代码时,我都会得到这个错误,

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

我转到我的项目文件夹,更改了“staff”和“everyone”的权限。我把它做得既能读又能写。然而,这并没有起到任何作用,我仍然得到相同的错误。

下面是我的代码,

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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56386244

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档