I have a program that cycles through directories, mutating a dictionary with keys of the file name, in this case 'black_arrow', but when i test it, i get this obscure error:
Traceback (most recent call last):
File "C:\Users\Michael\Desktop\game\dicts.py", line 17, in <module>
print(GetPics())
File "C:\Users\Michael\Desktop\game\dicts.py", line 13, in GetPics
load_attacks(dic)
File "C:\Users\Michael\Desktop\game\dicts.py", line 12, in load_attacks
dictionary [img[:-4]]=pg.image.load(img)
pygame.error: Couldn't open black_arrow.png
i tried this through the python shell, and it worked perfectly. i also tried calling pygame.init() which i did not think would do anything, and it did not. this is the main code:
def GetPics(dic={}):
'''
return a dictionary whose keys are the filename, and values are
he image itself.
'''
import pygame as pg, os
try:os.chdir('data')
except FileNotFoundError:
pass
def load_attacks(dictionary):
'''
adds keys for attacks to dictionary.
'''
Cpath='Attacks\\'
DirList=os.listdir(Cpath)
for Dir in DirList:
for img in os.listdir(Cpath+Dir):
dictionary [img[:-4]]=pg.image.load(img)
load_attacks(dic)
if __name__ == '__main__':
a={}
GetPics(a)
print(a)
(put in one file)