我在何处以及如何在Drive API上删除由Google文档创建的空白行?

时间:2018-04-03 08:20:58

标签: python google-api google-drive-api google-api-python-client

似乎在使用他们的API从Google文档更新或下载文件的过程中,Google会为每一个空白行添加一个新行。请参阅:Google Drive API on upload--where are these extra blank lines coming from?

我试图弄清楚如何摆脱Google创建的新线条,同时保留我自己有意放置的新线条。

我发现很难确定目标何时发生,以便剥离\ r或\ n。

我认为可能会在下载过程中发生,但我似乎无法将此文件打印出来:

def download_file(service, file_id, filepath):
    request = service.files().export_media(fileId=file_id, mimeType='text/plain')
    fh = io.BytesIO()
    downloader = MediaIoBaseDownload(fh, request)
    done = False
    while done is False:
        status, done = downloader.next_chunk()
        print("Download %d%%." % int(status.progress() * 100))
    with io.open(filepath,'wb') as f:
        fh.seek(0)
        f.write(fh.read())
        # mylist = f.read()

        # final = [line.rstrip('\n') for line in f]  

当我写入最终将在云端硬盘上传的文件时,print显示没有迹象表明有任何流氓新线路。事情看起来应该是这样的:

    with open("file_b.txt", "a+") as f:
        readfile = f.readlines()
        # readfile = [line.rstrip('\n') for line in f]
        # readfile = readfile.splitlines()
        print("read", readfile)
        # readfile.remove('\n')
        list2 = [a for a in readfile if a != '\n']
        print("newread", list2)
        # for line in readfile:
        #     print(line)
        #     line.replace('\n', '')
        # print("replaced", readfile)
        # readfile.
        # mylist = [line.rstrip('\n') for line in myfile]
        # print(mylist)
        list2.extend(data)

        print("2", list2)
        for item in list2:
            f.write(item)  
似乎什么都没有用。

如何从Google云端硬盘中删除这些虚线?

0 个答案:

没有答案