我将文本文件上传到了我的Google驱动器,我想知道如何使用python将文本附加到该文件,以及拥有该python文件的exe文件的其他人也如何附加它(所以它也适用于其他人)。我将该文件设置为可共享的链接,并可以使用该链接编辑该文本文件。我尝试使用urllib.request.urlopen,但它表示应该是str,字节而不是HTTP响应。使用urlopen,我可以打印该文本文件包含的内容,但由于某种原因无法写入该文件。也认为这应该用pydrive完成,但我不知道如何做。
这要感谢Martin Schere和Tanaike的澄清和指导,谢谢!附加文本用“ \ n”完成,因为我不知道其他任何方法,但是可以。
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gauth=GoogleAuth()
drive=GoogleDrive(gauth)
fileList=drive.ListFile({'q': "'root' in parents and trashed=false"}).GetList()
for files in fileList:
print('title: %s, id: %s' % (files['title'],files['id']))
if files['title'] == 'user_info.txt':
files.GetContentFile("user_info.txt")
update = files.GetContentString() + "\ntest"
files.SetContentString(update)
files.Upload()
break
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句