【问题标题】:Specify file download location using PyDrive?使用 PyDrive 指定文件下载位置?
【发布时间】:2020-07-03 15:40:21
【问题描述】:

我目前正在尝试使用 PyDrive 从 Google Drive 下载文件,但只能将文件下载到与我的 Python 程序相同的位置。有没有办法指定文件的下载位置?这就是我目前下载文件的方式。

    if file1['title'] == file_name:
      file2 = drive.CreateFile({'id': file1['id']})
      print('Downloading file %s from Google Drive' % file2['title']) 
      file2.GetContentFile(file_name)  # Save Drive file as a local file

【问题讨论】:

    标签: python pydrive


    【解决方案1】:

    尝试以下操作:

    if file1['title'] == file_name:
          location = "Path/where/you/want/to/save/"
          """
          if you are in linux and want to save it to documents try following
          location = "~/Documents/"
          the last forward slash i.e. '/' is important
          """
    
          full_path = location + file_name
    
          file2 = drive.CreateFile({'id': file1['id']})
          print('Downloading file %s from Google Drive' % file2['title']) 
          file2.GetContentFile(full_path)
    

    【讨论】:

    • 谢谢!我认为这应该足以作为替代方案,但是否也可以提示文件资源管理器加载并使用 GUI 指定下载位置?
    • @ancient 因为你需要一个用于 python 的 GUI 包,比如tkinter。您可以看到以下问题以了解您的要求:stackoverflow.com/questions/3579568/…
    猜你喜欢
    • 2020-01-16
    • 1970-01-01
    • 2014-10-04
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 2019-06-25
    • 1970-01-01
    相关资源
    最近更新 更多