IOError: [Errno 13] Permission denied: while writing to a file in windows python

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • madhuri124
    New Member
    • Oct 2018
    • 1

    IOError: [Errno 13] Permission denied: while writing to a file in windows python

    I am trying to write to a file inside folder.But it is failing with below error.Please help.

    Traceback (most recent call last):
    File "C:/Users/admin/Desktop/scripts/de.py", line 6, in <module>
    with open(mypath,"w+ ") as x:
    IOError: [Errno 13] Permission denied: 'C:/Users/admin/Desktop/scripts25/hj214/f.txt'

    Here is my code:
    import os
    mypath ="C:/Users/admin/Desktop/scripts25/hj214/f.txt"
    if not os.path.exists( mypath):
    os.makedirs(myp ath,0755);
    print"Path is created"
    with open(mypath,"w" ) as x:
    x.write("This is a boy")
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    is mypath a directory
    Code:
    os.makedirs(mypath,0755)
    or a file
    Code:
    with open(mypath,"w") as x:
    it can't be both.

    Comment

    Working...