secret_msg
和路径作为参数
secret_msg
的内容。我该怎么做呢 ?它说错误'str'对象没有属性'write' 4.关闭文件
返回: 该函数没有返回参数
message_parts=[secret_msg_3, secret_msg_1, secret_msg_4, secret_msg_2]
final_path= user_data_dir + '/secret_message.txt'
#Code starts here
secret_msg = " ".join(message_parts)
def write_file(secret_msg, path) :
open("path" , 'a+' )
path.write(secret_msg)
path.close()
write_file(secret_msg,final_path)
print(secret_msg)
答案 0 :(得分:0)
您需要open
文件,然后调用[]
方法。
这里是一种方式:
write
或使用def write_file(secret_msg, path):
f = open(path, 'a+')
f.write(secret_msg)
f.close()
:
with
我建议您看看How to write a file with Python。
希望有帮助!