python - 从 Python 中的文件夹名称中删除 ./
问题描述
我正在运行以下代码:
foldarz = [ f.path for f in os.scandir('.') if f.is_dir() ]
print(foldarz)
这将正确打印文件夹名称,但前面带有“.\”。我不想要“。\”。
我知道我可以拆分字符串等,但我认为有更好的方法而不必调用另一个函数。
解决方案
你可以这样做os.path.basename
:
foldarz = [os.path.basename(f) for f in os.scandir('.') if f.is_dir()]
推荐阅读
- ios - 将字符串转换为 `dd MMM yyy` 格式的日期
- batch-file - findstr 和 && 不一起玩
- python - 如何更改 Squish 中 waitForObject 函数使用的默认超时
- javascript - 为什么 chrome 在我的 JS 上抛出错误,但在 IE FF Android 和 Safari 中运行良好?
- java - ActiveMQ 在大约 10 000 条消息后给出:“无法连接到代理 URL:tcp://localhost:61616”
- sql - 将整数列表插入数据库列
- r - R:对具有两个条件的列求和
- tensorflow - 使用 GTX 1050 ti,tensorflow gpu 内存使用率 100%,但加载 ~0
- angular - Prod 构建在 Angular 5 惰性路由中失败
- vb.net - 使用FTP快速下载许多小文件