python - TypeError:join() 参数必须是 str、bytes 或 os.PathLike 对象,而不是“元组”
问题描述
我想处理我的所有文件path
。如果它是一个 zip 文件,我想将其内容提取为img
.
from pathlib import Path
import pandas as pd
import zipfile
import os
import sys
import pathlib
path = "./CODEX/input/"
for filename in os.walk(os.getcwd()):
with open(os.path.join(os.getcwd(), filename), 'r') as f:
# Antibody information
ab = pd.read_excel("HUBMAP B004 codex antibodies metadata.xlsx")
# TODO: Rename antibody_name column so that it matches channelNames.txt
# CODEX images
if filename.endswith(".zip"):
img = zipfile.ZipFile(os.path.abspath(filename)).extractall(path)
print(img)
> --------------------------------------------------------------------------- TypeError Traceback (most recent call
> last) /tmp/ipykernel_18751/2066110210.py in <module>
> 1 for filename in os.walk(os.getcwd()):
> ----> 2 with open(os.path.join(os.getcwd(), filename), 'r') as f:
> 3 # Antibody information
> 4 ab = pd.read_excel("HUBMAP B004 codex antibodies metadata.xlsx")
> 5 # TODO: Rename antibody_name column so that it matches channelNames.txt
>
> /usr/lib/python3.8/posixpath.py in join(a, *p)
> 88 path += sep + b
> 89 except (TypeError, AttributeError, BytesWarning):
> ---> 90 genericpath._check_arg_types('join', a, *p)
> 91 raise
> 92 return path
>
> /usr/lib/python3.8/genericpath.py in _check_arg_types(funcname, *args)
> 150 hasbytes = True
> 151 else:
> --> 152 raise TypeError(f'{funcname}() argument must be str, bytes, or '
> 153 f'os.PathLike object, not {s.__class__.__name__!r}') from None
> 154 if hasstr and hasbytes:
>
> TypeError: join() argument must be str, bytes, or os.PathLike object,
> not 'tuple'
解决方案
您可以使用 os.listdir() 代替 os.walk()
for filename in os.listdir(path):
pass
推荐阅读
- node.js - 我想通过 npm 安装一些东西,但它说'错误'和'checkPermissions Missing'
- apache - 无法使用 vagrant 从主机解析 IP
- amazon-web-services - AWS RDS 无法设置启用删除保护的备份保留期
- unity3d - unity linux editor import mp3 引发错误:AudioClip 导入期间出现未指定错误
- react-native - 使用反应导航延迟深度链接导航
- java - Antlr 主类错误:MyListener 无法解析为类型
- google-apps-script - 通过 Twilio 和 Google 应用脚本发送彩信
- node.js - MongoDB/节点查找/匹配
- javascript - 数组内的Javascript对象
- java - 在光线追踪中,图像平面在哪里?