相关疑难解决方法(0)

如何使用Python清空文件

在Unix shell中我可以这样做来清空一个文件:

cd /the/file/directory/
:> thefile.ext
Run Code Online (Sandbox Code Playgroud)

我将如何在Python中执行此操作?

是这样os.system的方式,我不知道如何,因为我必须在彼此之后发送2个动作,即cd然后是:>.

python

66
推荐指数
2
解决办法
9万
查看次数

使用 Python 清空 Google Drive 垃圾箱

我试图用 API 清空我的谷歌驱动器垃圾箱,但没有运气。我曾尝试使用请求库,脚本运行没有错误,但驱动器垃圾没有被删除。我已经能够通过 API 获取文件,但不能删除或清空垃圾箱。似乎我应该能够只发送一个 http 请求,但这对我来说比看起来要困难得多。任何建议将不胜感激。这是我所拥有的。我什至没有收到 json 响应。

from __future__ import print_function
import httplib2
import os
import requests

from apiclient import discovery
from oauth2client import client
from oauth2client import tools
from oauth2client.file import Storage


try:
    import argparse
    flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
except ImportError:
    flags = None

SCOPES = 'https://www.googleapis.com/auth/drive'
CLIENT_SECRET_FILE = 'C:\Scripts\Link Expiration\client_secret.json'
APPLICATION_NAME = 'Drive API Delete Trash'

def get_credentials():
    """Gets valid user credentials from storage.

    If nothing has been stored, or if the stored credentials are invalid,
    the …
Run Code Online (Sandbox Code Playgroud)

python google-api google-drive-api google-api-python-client

2
推荐指数
1
解决办法
2442
查看次数