FileNotFoundError: [Errno 2]
大家能不能帮我看看这个错误原因和要怎么修改呢,谢谢啦错误原因:
with open('data.json', 'r', encoding="utf-8") as f:
FileNotFoundError: No such file or directory: 'data.json'
import random
import json
with open('data.json', 'r', encoding="utf-8") as f:
data = json.loads(f.read())
d = int(input("杂诗几句?"))
e = int(input("一句几字?"))
while d:
f = ''
while True:
c = random.randint(0, len(data) - 1)
if len(f) + len(data) > e:
pass
else:
f += data
if len(f) == e:
print(f, end=' ')
break
d -= 1
没有找到 data.json 文件,检查下代码和文件是否在同一目录下,文件名是否正确
页:
[1]