结构保存文件在服务器上,而不是我的笔记本电脑上

2024-04-26 00:43:26 发布

您现在位置:Python中文网/ 问答频道 /正文

所以在一个fab任务中,我试图在服务器上保存一个文件,而不是在我的笔记本电脑上。 所以这节省了文件.txt我想把它保存在服务器的/tmp上

with open('/tmp/file.txt', 'a') as f:
    f.writelines("\n".join(names))
    f.write('\n')

Tags: 文件服务器txtwritelinesnamesaswithopen
2条回答

你可以append

或者只是像这样使用run

for name in names:
    command = "echo {} >> /tmp/file.txt".format(name)
    run(command)

您可以使用^{}命令。它将文件上载到远程主机。在

from fabric.context_managers import cd
from fabric.operations import put

with cd('/path/in/remote/host/'):
    put('/path/to/local/file.txt', 'file.txt')

相关问题 更多 >