python - 如何在 Vscode 中访问另一个文件夹中的文件?
问题描述
所以我的项目中有2个文件夹。Streamlit 文件夹和数据文件夹。我在 Streamlit 中拥有的程序需要访问数据文件夹中的图像。我如何访问这些?
我试过
streamlit.image("data/image.jpeg", width=680)
这抛出了 No such file or directory: 错误。
解决方案
当我编写一个脚本来向收件人发送一堆带有不同图像的电子邮件时,我确实需要类似的东西。我所做的是:
#jpg 可以是 tif 或任何其他文件类型。我使用 *.tif,因为我需要一个图像列表。
import glob
target_folder = glob.glob("C:\\Users\\Username\\Destination\\Folder\\filename.jpg")
def open_image_attachment():
_image_list = []
for _one_image_attachment in target_folder:
_attachment_ = open(_one_image_attachment, 'rb')
_file_name = os.path.basename(_one_image_attachment)
_part = MIMEBase('application','octet-stream')
_part.set_payload(_attachment_.read())
_part.add_header('Content-Disposition',
'attachment',
filename = _file_name)
_image_list.append(_part)
return _image_list
推荐阅读
- facebook - 如何不将 Facebook 聊天机器人与正常对话混为一谈
- java - 创建 Do-While 循环后修复 java.lang.NullPointerException
- python - Pandas 数据框无法从 CSV 中绘制 x 值
- python - 如何在 python 脚本中获取两个 svn 修订版的完整上下文差异?
- python - Jinja 模板引擎过滤器
- protocol-buffers - google.protobuf.Empty 对向后兼容有危险吗?
- android - android centerCrop 比例与顶部开始对齐
- c# - 使用内联连接检查 IsNullOrEmpty
- sql - SQL中的空位列
- delphi - Delphi WinINet Api 编码