1

I am trying to open a file inside the two folders

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

But it is giving me there error

There is no such file or directory: 'inventory.1.txt'

But I know for a fact that there is 'inventory.1.txt' inside PlayerFiles/PlayerItems.

What am I doing wrong? Is it because it is a string?

I used this question to get where I am now.

1 Answer 1

2

If you have the path and the filename, as constructed with your join, what is glob doing there? It looks like you're opening a single file.

import os
wPlayer = '1'
playeritems = 'PlayerFiles/PlayerItems'
with open(os.path.join(playeritems,'inventory.%s.txt' % wPlayer), 'r') as wPs:
  #do stuff with wPs
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! For some reason I thought I had to find the file first.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.