Python Forum
PermissionError while running function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PermissionError while running function
#14
Well, it's not a file but a directory, but as I understand that shouldn't make a difference? The directory does exist, and the path should be correct as it works when calculating the files in that directory in the same function, and I use the same mca_file there. The complete function is this

def function(n_pts, n_chnl, mca_file):
    print('Checking that n_files divided by n_pts is an integer...')
    n_files = 0
    for path in pathlib.Path(mca_file).iterdir():
        if path.is_file():
           n_files += 1
    if n_files % n_pts == 0:
        print('Done!')
    else:
        print('Not an integer, check the number of files in your mca folder')
        raise SystemError
    print('Summing up mcas in 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:
            filename = mca_file.format(mca)
            print('DEBUG: is file? ', os.path.isfile(filename), filename)
            mcadata[:, energy_point] += np.loadtxt(filename)
            #mcadata[:, energy_point] += np.loadtxt(mca_file.format(mca))
    print('Done!')
    return mcadata
and the code does the first part well, dividing n_files with n_pts using the same exact directory named as 'mca_file'. Perhaps the os.listdir command doesn't work here, then? Also, huge thanks for your help so far!
Reply


Messages In This Thread
RE: PermissionError while running function - by Laplace12 - Aug-01-2020, 04:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  the order of running code in a decorator function akbarza 2 570 Nov-10-2023, 08:09 AM
Last Post: akbarza
  Class function is not running at all even though it is clearly run in the code SheeppOSU 2 2,156 Sep-26-2020, 10:54 PM
Last Post: SheeppOSU
  Fixing "PermissionError: [Errno 13] Permission denied" puredata 17 72,964 Mar-09-2020, 03:20 PM
Last Post: syssy
  Running function from parent module which has a loop in it. ta2909i 1 2,719 Nov-18-2019, 07:04 PM
Last Post: Gribouillis
  PermissionError: [Errno 13] Permission denied: error leviathan54 2 46,746 Apr-20-2019, 12:51 AM
Last Post: leviathan54
  [python] PermissionError: [Errno 13] Permission denied akamouch 1 42,490 Feb-07-2019, 03:28 PM
Last Post: ichabod801
  PermissionError Quavin 1 2,789 Dec-02-2017, 10:34 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020