读写Dropbox文件而不使用外部文件

时间:2015-02-26 19:16:01

标签: python dropbox dropbox-api

我见过的所有Dropbox API SO questionsofficial documentation仅提供了上传Dropbox外部文件,然后使用put_file和{{1将Dropbox文件下载到外部文件的示例分别。

有没有办法在Dropbox文件系统中专门读写文件而不创建外部文件?

1 个答案:

答案 0 :(得分:1)

您可以将字符串直接发送到put_file。它不必是文件对象:

# ... insert example code in OP's SO link to get client object

# uploading
s = 'This is a line\n'
s += 'This is another line'
response = client.put_file('/magnum-opus.txt', s)

使用get_file收到的文件可以直接访问而无需创建外部文件:

# downloading
f, metadata = client.get_file_and_metadata('/magnum-opus.txt')
for line in f:
    print line
f.close()
相关问题