用Python实现以下功能 1、创建文件,名称为english_song”,将 歌词按行输入, 歌词是“every night in ay dreane,i see you,i feel you. that is how I lcnow you go an.far across the distance. and spaces betueen us,you have cane to showr you go on. near far,wherever you are. I belleve,that the heart does go on. once nore you open the door,and youre here in ny heart. and ay beart will go on and on,lovel can touch us one tine.”2、将文件重命名为“my heart will go on”3、对文件创建副本为“back- up”4、关闭文件
时间: 2023-12-10 17:39:14 浏览: 103
以下是Python代码实现:
```python
# 创建并写入文件english_song
with open("english_song.txt", mode="w", encoding="utf-8") as f:
f.write("every night in ay dreane,i see you,i feel you. that is how I lcnow you go an.far across the distance. and spaces betueen us,you have cane to showr you go on. near far,wherever you are. I belleve,that the heart does go on. once nore you open the door,and youre here in ny heart. and ay beart will go on and on,lovel can touch us one tine.")
# 将文件重命名为my heart will go on
import os
os.rename("english_song.txt", "my heart will go on.txt")
# 对文件创建副本back-up
import shutil
shutil.copyfile("my heart will go on.txt", "back-up.txt")
# 关闭文件
f.close()
```
阅读全文