相对路径在 Python 中不起作用

Relative path not working in Python

我的 Python 脚本无法在以下脚本中解析 Linux 服务器上的相对路径:

import boto3
import os

conn = boto3.client('s3', region_name="eu-west-1", endpoint_url="https://example.com", config=Config(signature_version="s3", s3={'addressing_style': 'path'}))
conn.download_file('mytestbucket22', 'file.csv', os.path.join(os.getcwd(), 'static', 'filecache', 'file.csv'))

错误:

[Errno 2] No such file or directory: '/home/vcap/app/static/filecache/file.csv.D3e3D7aF'

但是,当我这样做时,它会起作用并将文件保存到我的脚本路径中。

conn.download_file('mytestbucket22', 'file.csv', 'file.csv')

我的文件夹和文件结构如下所示:

--script.py
--static
----filecache

如何将文件保存到文件夹filecache?谢谢

conn.download_file('mytestbucket22', 'file.csv', os.path.join(os.getcwd(), 'static', 'filecache', 'file.csv'))

上面使用的模块、常量和函数的文档参考:

我会用

conn.download_file('mytestbucket22', 'file.csv', os.path.join(os.path.dirname(sys.argv[0]), 'static', 'filecache', 'file.csv'))