python - 如何在 macOS 中使用 python 附加文件夹中存在的多个 .dmg 文件
问题描述
多个 .dmg 文件存在于特定文件夹中,使用 python 如何迭代地挂载这些 .dmg 文件。我尝试了以下代码
import os
path = '/Users/kat/Desktop/pro'
os.chdir(path)
for i in os.scandir(path):
print(i)
os.system("hdiutil attach i")
但我得到“hdiutil”命令未找到错误。任何建议都会有所帮助。
解决方案
我想你想要更像这样的东西:
import os, glob
os.chdir('/Users/kat/Desktop/pro')
for i in glob.glob("*.dmg"):
print(i)
os.system(f'hdiutil attach "{i}"')
Python “f-strings”在此处描述。
推荐阅读
- python - 为什么这个 else 语句不返回 False?
- google-cloud-platform - 有没有办法在向其发送流量之前测试完全托管的 Cloud Run 修订版?
- bash - 无法弄清楚如何实现这个bash参数
- vue.js - vuetify 数据表不显示数据
- reactjs - 反应:res.json() 数据未定义
- python - 抓取中途停止爬行
- android - 如何在 Android 登录中获取 Firebase 身份验证令牌
- sql - 在 Go 中推广 *sql.Rows 扫描
- flutter - 未处理的异常:MissingPluginException(在通道 com.tekartik.sqflite 上找不到方法 getDatabasesPath 的实现)
- android - CustomView 继承自 LinearLayout 但我不知道上下文是什么