在Python中。。。如何从.txt文件中提取name和ext

2024-05-08 03:48:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我的档案就是这样。你知道吗

  label0/index.jpeg 0

  label1/index.jpeg 1

我的密码是

 def add_ext_name(cls, path, ext_name): 
    name, ext = os.path.splitext(os.path.basename(path))
    added = os.path.join(os.path.dirname(path), name + ext_name + ext)
    return added

错误是

 def basename(p):
   """Returns the final component of a pathname"""
     p = os.fspath(p)
     sep = _get_sep(p)
     i = p.rfind(sep) + 1

TypeError: expected str, bytes or os.PathLike object, not ImageProperty

我哪里出错了?你知道吗


Tags: pathnameadd密码addedindexosdef