python - 试图将目录的所有图片发送给 Telegram bot 用户
问题描述
我正在尝试将文件夹的所有图片发送给机器人用户。这是我尝试过的,但它不起作用,甚至没有出现任何错误。
path = '~/Documents/mypath/pics'
files = []
# r=root, d=directories, f = files
for r, d, f in os.walk(path):
for file in f:
if '.jpg' in file:
files.append(os.path.join(r, file))
for f in files:
telegram_bot.sendPhoto (chat_id, f)
这里有什么问题以及如何解决?
更新:我试过telegram_bot.sendPhoto(chat_id, open(f , 'rb'))
了,它有效,但它多次发送相同的图片。
解决方案
推荐阅读
- google-sheets - 如何组合 2 个查询导致来自 Google 表格的单个查询
- javascript - 如何在 asp.core MVC React 应用程序中注册 JS 引擎?
- python - django.db.utils.IntegrityError:安装夹具时出现问题
- java - 包含自身作为元素的 ArrayList 的哈希码
- python - 如何根据特定键比较python字典
- c++ - 执行用 C++ 编写的 .exe 的问题(使用 mingw 编译器)
- python - 将 DataFrame 中的每个唯一值重塑为列
- php - $row 将在此返回什么
- regex - 我如何将变量多行 perl 正则表达式与不同的规则匹配
- c# - 如何有条件地从 ASP.NET Core 注册中删除控制器并添加到 ServiceCollection