【发布时间】:2018-12-14 14:43:57
【问题描述】:
我正在尝试使用以下代码创建一个 .txt 文件并将其移动到指定文件夹,但我得到 PermissionError: [WinError 32] The process cannot access the file because it is being used by another进程:'C:\Users\Emre\Desktop\testbot\asdf\testuser.txt'
这个错误之后是脚本在脚本运行的目录和我希望shutil将txt文件移动到的目录中创建一个txt文件。我该怎么办?提前致谢。
import shutil
file = open("{}.txt".format(source), "w")
file.write("username = {}\n".format(source))
file.write("user_points = 200\n")
file.close
shutil.move("C:\\Users\\Emre\\Desktop\\testbot\\asdf\\{}.txt".format(source), "C:\\Users\\Emre\\Desktop\\testbot\\asdf\\users")
self.bot.say(channel, "You have been successfully registered, {}!".format(source))
【问题讨论】:
标签: python python-3.x