好的,这是一个使用 Python 写的保存文件的函数的例子:
def save_file(filename, content):
with open(filename, 'w') as f:
f.write(content)
这个函数接受两个参数:filename
和 content
。filename
是你想保存的文件的文件名,content
是你想保存到文件中的内容。
使用这个函数时,你可以这样调用它:
save_file('myfile.txt', 'This is the content of my file.')
这会在当前目录下创建一个名为 myfile.txt
的文件,并将字符串 'This is the content of my file.'
保存到文件中。
希望这能帮到你!