python 3.4.3无法写入桌面文件夹

时间:2015-12-12 16:38:42

标签: python python-3.x

我有一个简单的代码来编写特定文件夹中的文件。系统在文件夹中创建文件但无法在其上写入。它在Windows上,我检查了IDE写访问(Pycharm),他们似乎很好。文件为空。 以下代码是读取我是否可以写或确保前一个完成。它不是将短字符串写入文件。我在命令行上尝试了它,但它也没有在那里工作。

with open ('C:/Users/***/Desktop/***/output.log',mode ='w', encoding ='utf-8') as a_file:
    a_file.write ="test"

with open ('C:/Users/***/Desktop/***/output.log', encoding ='utf-8') as a_file:
    print(a_file.read())

1 个答案:

答案 0 :(得分:3)

write是一种方法(函数),您需要调用,而不是分配给它。

with open ('C:/Users/***/Desktop/***/output.log', mode='w', encoding='utf-8') as a_file:
    a_file.write("test")  # <---