Permission denied: 'C:\\Users\\Public\\Desktop\\From py.txt'

接上一篇文章 加了r以后报错
import csv

filename = ‘D:\软件安装包\python\《Python编程:从入门到实践》源代码文件\chapter_16\sitka_weather_07-2014.csv’
with open(filename) as f:
reader = csv.reader(f)
row_reader = next(reader)
# print(row_reader)

a = []
for line in reader:
    b = int(line[1])  #提取 第2列 字符串为数字
    a.append(b)
# print(a)

filename1 = r’C:\Users\Public\Desktop\From py.txt’
with open(filename1, ‘w’) as c:
c.write(a)

“D:\install program\python\python.exe” D:/test1/test.py
Traceback (most recent call last):
File “D:/test1/test.py”, line 16, in
with open(filename1, ‘w’) as c:
PermissionError: [Errno 13] Permission denied: ‘C:\Users\Public\Desktop\From py.txt’

Process finished with exit code 1

已解决:
使用管理员帐户登陆电脑后,右击C:\Users\Administrator\Desktop目录,选择属性,在弹出的文件夹属性设置窗口中选择安全,添加你需要具有此文件访问权限的用户帐户,然后确认即可。

你可能感兴趣的:(Permission denied: 'C:\\Users\\Public\\Desktop\\From py.txt')