提问人:Nare Avetisyan 提问时间:11/20/2022 最后编辑:WoodfordNare Avetisyan 更新时间:11/20/2022 访问量:33
如何从一个文件读取到另一个文件?
How to read from one file to another?
问:
我必须在 Python 中创建两个函数,一个用于读取文件,另一个用于将文件内容复制到另一个函数。我还必须对我从第一个文件复制的文本进行凯撒密码,但我还没有做到这一点,所以我只是在文本上写了一个随机操作,这是代码:
def read_file(path):
with open(path, "r") as fd:
return fd.read()
def create_file(path, text):
with open(path, "w") as fd:
return fd.write(text)
def caesar_encrypt(source: str, dest: str, shift: int = 3):
text = read_file(source)
text = '_'.join(text.split('0'))
create_file(dest, text)
caesar_encrypt('wwww', 'w2.txt')
它在第 2、12 和 17 行以及最后一行给了我一个错误,说“wwww”不存在(如果它不存在,它不需要创建它吗?
答: 暂无答案
评论
'wwww'
source
read_file()
path
path