Home > OS >  Can't find a JSON file even though they are in the same directory
Can't find a JSON file even though they are in the same directory

Time:07-15

I'm having a problem opening a JSON file, because it says that is doesn't exists but, it does, it is in the same directory, here, you can see it:

enter image description here

But even though they are in the same folder, it says that it doesn't exist:

enter image description here

Here is the code where outputs the error:

with open('warn.json', 'r', encoding='utf-8') as f:
    guilds_dict = json.load(f)
    if str(id) in guilds_dict:
        guilds_dict[str(id)]  = warns
    else:
        guilds_dict[str(id)] = warns

CodePudding user response:

Try to use:

with open('/root/Nasgar/NasgarBot/cogs/moderation/warn.json', 'r', encoding='utf-8') as f:
    guilds_dict = json.load(f)
    if str(id) in guilds_dict:
        guilds_dict[str(id)]  = warns
    else:
        guilds_dict[str(id)] = warns

This should work.

CodePudding user response:

You can try by changing the name. Secondly, open the file first and then do the other tasks. Check that code is opening your file or not.

CodePudding user response:

It works, my question is: Where is defined "warns"? what's it supposed to do?

enter image description here

  • Related