我正在尝试打开两个文件夹中的文件

import glob
import os
wPlayer = '1'
playeritems = 'PlayerFiles/PlayerItems'
with glob.glob(os.path.join(playeritems, open('inventory.%s.txt' % wPlayer, 'r'))) as wPs:
  #do stuff with wPs


但这给了我错误


  没有这样的文件或目录:'inventory.1.txt'


但是我知道一个事实,PlayerFiles / PlayerItems内部有'inventory.1.txt'

我究竟做错了什么?是因为它是一个字符串?

I used this question to get where I am now.

最佳答案

如果您具有连接所构造的路径和文件名,那么glob在那里做什么?看来您正在打开一个文件。

import os
wPlayer = '1'
playeritems = 'PlayerFiles/PlayerItems'
with open(os.path.join(playeritems,'inventory.%s.txt' % wPlayer), 'r') as wPs:
  #do stuff with wPs

09-27 09:13