根据文件名分割文件路径列表

我大约有1000个文件,其中包含数字文件名。我试图根据文件名中的数字将文件名列表分成两部分。这是我正在使用的代码:


files = glob.glob('/content/drive/My Drive/Share/Data/Processed/*.npy')
for fileNum in range(0,len(files)):
  date = int(os.path.splitext(os.path.basename(files[fileNum]))[0])
  if date <= sampleDate:
    if trainFiles in locals():
      trainFiles = np.vstack((trainFiles,files[fileNum]))
    else:
      trainFiles = files[fileNum]
  else:
    if testFiles in locals():
      testFiles = np.vstack((testFiles,files[fileNum]))
    else:
      testFiles = files[fileNum]

我遇到错误:

---> 12     if testFiles in locals():
     13       testFiles = np.vstack((testFiles,files[fileNum]))
     14     else:

TypeError: unhashable type: 'numpy.ndarray'

问这个错误真的没有意义,因为回头看这段代码,我意识到它的废话……有人可以告诉我正确的方法,因为我知道这不是它。

iCMS 回答:根据文件名分割文件路径列表

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/1826868.html

大家都在问