How to write this json file?

krishna511: <p>I know this question is not directly related, But in my pytorch model I need to create this json file first.</p>
<pre><code class="lang-auto">import glob
import json
import os

LABEL = {
    'neu': '01',  #: 'neutral',
    'fru': '02',  #: 'calm',
    'hap': '03',  #: 'happy',
    'sad': '04',  #: 'sad',
    'ang': '05',  #: 'angry',
    'fea': '06',  #: 'fearful',
    'exc': '07',  #: 'disgust',
    'sur': '08',  #: 'surprised'
    'xxx': '09',  #: 'other'
}


PATH_TXT = glob.glob("E:/dataset/data/IEMOCAP_full_release/*/dialog/EmoEvaluation/S*.txt")
PATH_WAV = glob.glob("E:/dataset/data/IEMOCAP_full_release/*/sentences/wav/*/S*.wav")

PAIR = {}


def getPair():
    for path in PATH_TXT:
        with open(path, 'r') as f:
            fr = f.read().split("\t")
            for i in range(len(fr)):
                if (fr[i] in LABEL):
                    PAIR[fr[i - 1]] = fr[i]


def rename():
    for i in PATH_WAV:
        for j in PAIR:
            if (os.path.basename(i)[:-4] == j):
                k = j.split('_')
                if (len(k) == 3):
                    name = os.path.dirname(i) + '/' + k[0] + '-' + k[1] + '-' + LABEL[PAIR[j]] + '-01-' + k[2] + '.wav'
                    os.rename(src=i, dst=name)
                    print(name)
                    '''
                    Ses01F_impro01_F000.wav
                    k[0]:Ses01F
                    k[1]:impro01
                    k[2]:F000
                    Ses01F-impro01-XX-01-F000.wav
                    '''
                elif (len(k) == 4):
                    name = os.path.dirname(i) + '/' + k[0] + '-' + k[1] + '-' + LABEL[PAIR[j]] + '-01-' + k[2] + '_' + \
                           k[3] + '.wav'
                    os.rename(src=i, dst=name)
                    print(name)
                    '''
                    Ses03M_script03_2_F032.wav
                    k[0]:Ses03M
                    k[1]:script03
                    k[2]:2
                    k[3]:F032
                    Ses03M-script03-XX-01-2_F032.wav
                    '''


if __name__ == '__main__':
    pairPath = "E:/Python_On_All_Dataset/IEMO/IEMOCAP"
    # if (os.path.exists(pairPath)):
    #     with open(pairPath, 'r') as f:
    #         PAIR = json.load(f)
    # else:
    getPair()
    with open('my.json', 'w') as f:
        json.dump(obj=PAIR, fp=f)
rename()

</code></pre>
<p>when I run this ''main" function its throwing an error: saying permission error</p>
<p>Now I am unable to run and regenerate the error because the second fun rename() is changing the filenames in my original dataset. So plz guide how to change this code at line</p>
<pre><code class="lang-auto">os.rename(src=i, dst=name)


</code></pre>
<p>so that the renamed files are stored in some other location, then probably I can save this dict name PAIR in json format.</p>
<p>Regards</p>

ptrblck: <p>I’m not if I understand the issue correctly, but guess you might change the <code>dst</code> location to store the files to another location.<br>
In any case, since this is unrelated to PyTorch I would recommend to post it on StackOverflow or any other general Python discussion board to get a faster and better answer.</p>

krishna511: <p><a class="mention" href="/u/ptrblck">@ptrblck</a> thank you, sir, actually I have already posted there no reply yet.</p>

ptrblck: <p>In that case could you explain the problem a bit more?<br>
It seems you’ve executed the script, some files were moved, but the script failed with a permission error (did you solve the permission issue?).<br>
Afterwards you wanted to continue the script, but are now running into issues since a subset was already moved?</p>

krishna511: <p>sir I am trying your previous suggestion.just changing <code>dst</code> lets see if it works for me. I will let you know sir.<br>
regards</p>

krishna511: <p><a class="mention" href="/u/ptrblck">@ptrblck</a> Hi sir, I have changed this <code>dst</code> to the required different folder as <code>'E:\\Python_On_All_Dataset\\IEMO\\long_codes\\multiscale_att_impro_only\\head_fusion-master\\IEMOCAP'</code>. But its throwing the error:</p>
<p><code>[WinError 183] Cannot create a file when that file already exists: 'E:/dataset/data/IEMOCAP_full_release\\Session1\\sentences\\wav\\Ses01F_impro01\\Ses01F_impro01_F000.wav' -&gt; 'E:\\Python_On_All_Dataset\\IEMO\\long_codes\\multiscale_att_impro_only\\head_fusion-master\\IEMOCAP'</code></p>
<p>Sir let me explain it again: Here I want to change the data files name which are stored in original directory of my dataset, and renamed files need to be stored at other location so that my original data files are not disturbed. But why is it saying these files already exist there. The destination folder IEMOCAP is empty <img src="https://discuss.pytorch.org/images/emoji/apple/frowning.png?v=9" title=":frowning:" class="emoji" alt=":frowning:"><br>
Regards</p>