0

I am trying to write the output of python script to a text file. The script runs for sometime and write the content to the file. But after sometime I get 'PermissionError: [Errno 13] Permission denied:'

Below is my script.

def ancestor_map(id):
    
    row_icd = umls[umls['AUI'] == id]        
    cui = row_icd.CUI.to_string(index=False)               
    
    if cui in df_mdr_pt_llt['CUI'].values:                   
        match = df_mdr_pt_llt[df_mdr_pt_llt['CUI'] == cui]
        match = match[["CODE", "STR", "TTY", "SDUI"]].drop_duplicates()
        match["icd_code"] = icd_code
        match["icd_term"] = icd_term
        match["level"] = level
        match["is_a"] = 'indirect_rel'

        match = match.loc[:, ["icd_code","icd_term","CODE","STR", "TTY", "SDUI", "level", "is_a"]]
        match.to_csv(r'indirect_mapping_icd10cm.txt', header=None, index=None, sep='\t', mode='a')
        
    else:
        print ('match not found: continue')

How can I modify my script to write the whole content without any error.

Any help is highly appreciated!

2
  • could you post the complete traceback of your error? You (or any other process) are not opening this file to check the contents while the program is running right? Commented Apr 21, 2023 at 10:53
  • No, I am not opening the file Commented Apr 21, 2023 at 10:55

1 Answer 1

0

before running your script make sure your text file is closed.

S0, i can suggest first close your text file if it is opened in any where and then run the script.

i think it will work.

Sign up to request clarification or add additional context in comments.

2 Comments

That sounds believable under Windows (I think, although I don't program with Windows). Under Linux it would be unlikely to cause a permissions error. Perhaps you should ask the OP for clarification regarding their OS platform.
Yes, it is windows

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.