Jul-30-2020, 01:27 PM
I need help understanding an error. I have created a function that's supposed to read all files in a specific folder and sum them. However, there is a PermissionError when trying to execute the code, and as I understand this comes if you're trying to write to that folder and don't have permission; but I'm not trying to create any files in that folder, simply read the files in there and sum them! So even if the error itself is not a python issue, there is then something strange about the function that I don't understand because it shouldn't be creating any files. The function is this:
def function(n_pts, n_chnl, mca_file): mcadata = np.zeros([n_chnl, n_pts]) for energy_point in range(n_pts): current_mca = os.listdir(mca_file) for mca in current_mca: mcadata[:, energy_point] += np.loadtxt(mca_file.format(mca)) print('Done!') return mcadataI have defined mca_file, which is the location of the folder in my computer.
PermissionError: [Errno 13] Permission denied: 'mca_file'So, is the function doing something it shouldn't? Listdir command is used to make a list of all the files that should be summed up, and then mcadata is defined as the sum.